genemu / GenemuFormBundle

Extra Form : Captcha GD, Tinymce, Recaptcha, JQueryDate, JQueryAutocomplete, JQuerySlider, JQueryFile, JQueryImage
587 stars 265 forks source link

Default value on entity autocomplete #397

Open Sashkan opened 9 years ago

Sashkan commented 9 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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.