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

Autocompete with symfony2.7 #412

Open
aimeric opened this issue Nov 1, 2015 · 5 comments
Open

Autocompete with symfony2.7 #412

aimeric opened this issue Nov 1, 2015 · 5 comments

Comments

@aimeric
Copy link

aimeric commented Nov 1, 2015

Hi,

I have the following error when I implement genemu_jqueryautocompleter_entity.

 Catchable Fatal Error: Argument 1 passed to Genemu\Bundle\FormBundle\Form\Core\DataTransformer\ChoiceToJsonTransformer::__construct() must implement interface Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface, instance of Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter given, called in /srv/www/Toolkit/vendor/genemu/form-bundle/Genemu/Bundle/FormBundle/Form/JQuery/Type/AutocompleterType.php on line 46 and defined

I fixed the error by editing: LegacyChoiceListAdapter

use Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter;

  /**
     * Constructs
     *
     * @param ArrayChoiceList $choiceList
     * @param boolean         $ajax
     */
    public function __construct($choiceList, $ajax = false, $widget = 'choice', $multiple = false)
    {
        if ($choiceList instanceof LegacyChoiceListAdapter){
            $this->choiceList = $choiceList->getAdaptedList();
        }
        else if($choiceList instanceof ChoiceListInterface){
            $this->choiceList = $choiceList;
        }

        $this->ajax = $ajax;
        $this->multiple = $multiple;
        $this->widget = $widget;
    }

but now i got a new error:

Notice: Undefined offset: 1 on file in vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php at line 213 


// Add ungrouped items directly
            self::addChoiceView(
                $choices[$value],
                $value,
                $label,
                $keys,


this is my PostType.php

<?php

namespace FLY\BookingsBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class PostType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('airport', 'genemu_jqueryautocompleter_entity', array(
                'route_name' => 'ajax_airport',
                'property' => 'airport',
                'multiple' => true,
                'class' => 'FLY\BookingsBundle\Entity\IataAirportCodes',


            ))

            ->add('departure')
            ->add('arrival')
            ->add('departuredate')
            ->add('arrivaldate')
            ->add('pounds')
            ->add('price')
            ->add('compagny')
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'FLY\BookingsBundle\Entity\Post'


        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'fly_bookingsbundle_post';
    }
}

Thank you :)

@aimeric
Copy link
Author

aimeric commented Nov 3, 2015

Any idea ? i'm still stack :(

@lealceldeiro
Copy link

Have anyone solved this issue? I'm stuck here too! I'm using Symfony 2.7.7

@aimeric
Copy link
Author

aimeric commented Jan 8, 2016

Hi lealceldeiro, i didn't found a way to solved my issue. if you want to pull your data from the database this is what you can do : ->add('lealceldeiro', 'genemu_jqueryselect2_entity', array( 'class' => 'MylealceldeiroBundle:lealceldeiro', 'property' => 'lealceldeiro', 'query_builder' => function(EntityRepository $er) { return $er->createQueryBuilder('u') ->groupBy('u.code') ->orderBy('u.lealceldeirot', 'ASC'); },) ) i'm using query_builder to speed up the research because i have more than 10.000 items. then in your twig file you can use select2 it will help you to have a better interface to search an element in your dropdown. https://select2.github.io/

@lealceldeiro
Copy link

aimeric thanks for the reaply. I've decided to try something different. Here is something related to what I did (http://stackoverflow.com/questions/32334289/adding-jquery-autocomplete-in-symfony2-entity-field)
I don't know yet if this is a better or a worse solution regarding to performance, but at least I got it working properly.
I'll try what you told me later.

@sensi
Copy link

sensi commented Jun 1, 2016

Issue allready exists. Also in symfony 2.8.x.

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

3 participants