Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value on entity autocomplete #397

Open
Sashkan opened this issue Jun 3, 2015 · 4 comments
Open

Default value on entity autocomplete #397

Sashkan opened this issue Jun 3, 2015 · 4 comments

Comments

@Sashkan
Copy link

Sashkan commented Jun 3, 2015

Hello,

Is it possible to "force" a choice on entity autocomplete ?

Let's say, I got a City entity. If I type Pari , My list will automatically display "Paris" as a choice. Unfortunately, if I immediately press Tab to get to the next form input, the Autocomplete will just remain on "Pari", and pop an error on form submit (Impossible to access an attribute ("name") on a NULL variable ("")). '

How can I force the input to select the first displayed result ?

@webdevilopers
Copy link

You can set the default values like with other Symfony forms too. Since your field is mapped to an entity, you will have to pass an entity to populate it.

Based on the example in the docs:

        $member = $em->find('AppBundle\Entity\Member', 1);

        $filterForm = $this->get('form.factory')->create(new MemberFilterType());
        $fFilterForm->setData(array(
            'member' => $member
        ));

Close?

@Sashkan
Copy link
Author

Sashkan commented Jul 14, 2015

I'm not sure to understand this: will it fill the form with the first element of my repository, or with the first element in the autocompletion list ?
Anyway, thank for your answer

Pierre Olivier TRAN06.79.63.36.78fr.linkedin.com/in/potran

Date: Tue, 14 Jul 2015 06:08:51 -0700
From: notifications@github.com
To: GenemuFormBundle@noreply.github.com
CC: ptran@student.42.fr
Subject: Re: [GenemuFormBundle] Default value on entity autocomplete (#397)

You can set the default values like with other Symfony forms too. Since your field is mapped to an entity, you will have to pass an entity to populate it.

Based on the example in the docs:

https://github.com/genemu/GenemuFormBundle/blob/master/Resources/doc/jquery/autocomplete/entity.md

    $member = $em->find('AppBundle\Entity\Member', 1);

    $filterForm = $this->get('form.factory')->create(new MemberFilterType());
    $fFilterForm->setData(array(
        'member' => $member
    ));

Close?


Reply to this email directly or view it on GitHub.

@webdevilopers
Copy link

Sorry, we are talking about different things. My answer is regarded to setting "default values".
Your problem seems to be with your javascript on client side.

@Sashkan
Copy link
Author

Sashkan commented Jul 14, 2015

yes, I'm sorry, I'm new to this bundle, I have to admit it is amazing, altough I still don't get all of it's awesomeness :).
Long story short, I was hoping to automatically fill the form input with the first element displayed in the jquery autocomplete list. Thank you for your answers !
Have a nice day

Pierre Olivier TRAN06.79.63.36.78fr.linkedin.com/in/potran

Date: Tue, 14 Jul 2015 06:28:08 -0700
From: notifications@github.com
To: GenemuFormBundle@noreply.github.com
CC: ptran@student.42.fr
Subject: Re: [GenemuFormBundle] Default value on entity autocomplete (#397)

Sorry, we are talking about different things. My answer is regarded to setting "default values".

Your problem seems to be with your javascript on client side.


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants