PUGX / PUGXAutoCompleterBundle

Add an autocomplete field to your Symfony forms
GNU Lesser General Public License v3.0
93 stars 38 forks source link

Symfony 3 #31

Closed bettinz closed 8 years ago

bettinz commented 8 years ago

Hello, I'm using Symfony 3. In FormType 'autocomplete' doesn't work

            ->add('book', 'autocomplete', array('class' => 'AppBundle:Book'))

I need to use

            ->add('product', 'PUGX\AutocompleterBundle\Form\Type\AutocompleteType', array(
                'class'=>'AppBundle\Entity\Product'
            ))

Also, Assetic is not available anymore, so

{% javascripts
    'js/jquery.js'
    'js/jquery-ui.js'
    '@PUGXAutocompleterBundle/Resources/public/js/autocompleter-jqueryui.js'
%}

doesn't work. Are known problems? Thank you

garak commented 8 years ago

I'll add a note about Symfony 3 in documentation. Assetic is still available, just install it (or do not use it, it's not mandatory)

dialogik commented 8 years ago

The documentation example still shows the Symfony2 approach. There seems to be a hint about Symfony3

In your FormType, change field type from entity to autocomplete

which at least would make sense in Symfony3 like this.

->add('name', 'autocomplete')

But it doesn't work. Instead it throws a

500 Could not load type "autocomplete"

exception. So another way in Symfony3 would be something like this

use PUGX\AutocompleterBundle\Form\Type\AutocompleteType;

...
->add('author', AutocompleteType::class, array(...))

but this throws a 500 Option "class" must be set exception as this constant seems to be unset.

And finally using the legacy method like this

->add('author', 'PUGX\AutocompleterBundle\Form\Type\AutocompleteType', array(
    'class'=>'AppBundle\Entity\Author'
))

throws a

500 Call to a member function getId() on string

Stack Trace in vendor\pugx\autocompleter-bundle\Form\Transformer\ObjectToIdTransformer.php at line 44

        return '';
    }
    return $object->getId();
}

I recommend to reopen this issue and collaboratively take a look into this and keep the documentation up to date...

dialogik commented 8 years ago

Or maybe I'm just missing something out here. In that case I'd be happy for a heads up :smiley:

garak commented 8 years ago

The error about ::class is your fault, you need a newer version of PHP. The last option you used, the one with the FQCN, is the one currently proposed by the docs, and it's supposed to work. Feel free to open an issue if you're able to create a situation where the bug is reproducible

dialogik commented 8 years ago

Hm, I'm using Symfony version 3.1.5 and PHP 7.0.6. What PHP version is required?

garak commented 8 years ago

Sorry, the error is not about ::class, is about class option missing

FacundoVelazco commented 3 years ago

I have same problem. image

Sorry, the error is not about ::class, is about class option missing

garak commented 3 years ago

@FacundoVelazco feel free to open an issue when you explain how to reproduce