Symfony2 - How to check the form type of an autocomplete object?

I have a form with the following fields:

$builder ->add('title', 'text') ->add('body', 'textarea') ->add('tags', 'entity', [ 'class' => 'AppBundle\Entity\Tag', 'choice_label' => 'name', 'expanded' => false, 'multiple' => true, ]); 

User can select multiple tags. Everything works perfectly. But now that the number of tags is becoming very large (over 20,000 tags), page rendering is becoming very slow because the entity type loads all the tags in selectbox. So I implement jQuery autocomplete selectbox to prevent the whole entity from loading, but when I submit the form, the validator still loads all the tags for validation! How can I solve this validation problem? Thanks!

+4
source share
1 answer

Instead of using the entity field type, use a simple text type that will take the identifier of the associated object. You also need to make a data converter to convert the sent identifier into an object object (and vice versa), which will be installed on the form data object.

Data Transformer Example

Validation will work as if it were an entity field type, thanks to a data transformer.

+5
source

All Articles