Symfony3 Tetranz/select2 - remote_route

Multi tool use
Symfony3 Tetranz/select2 - remote_route
I'm trying to use the select2entity-bundle for my project to implement auto-complete.
When using the builder, the specification is as follows :
$builder
->add('country', Select2EntityType::class, [
'multiple' => true,
'remote_route' => 'tetranz_test_default_countryquery',
'class' => 'TetranzTestBundleEntityCountry',
'primary_key' => 'id',
'text_property' => 'name',
'minimum_input_length' => 2,
'page_limit' => 10,
'allow_clear' => true,
'delay' => 250,
'cache' => true,
'cache_timeout' => 60000, // if 'cache' is true
'language' => 'en',
'placeholder' => 'Select a country',
// 'object_manager' => $objectManager, // inject a custom object / entity manager
])
What should be specified within the 'remote_route' parameter?
Why should my field be linked to a route? How and where should this route be configured? Should it be linked to a query?
Thanks for your help!
1 Answer
1
The select needs to update the values to display while he user is typing. It does this by sending a request to a controller you need to write, which collects the relevant values and returns them as json.
Create a controller that returns the list of items to display in the select, and use the name of the route you defined for that controller as the 'remote_route' parameter.
The format for the returned data is documented halfway down the page for the bundle on github https://github.com/tetranz/select2entity-bundle
Yeah, sorry I submitted to early and then the edit didn't take. Have updated.
– Phil Rennie
Jul 2 at 8:48
It works, thank you!!
– Guillaume
Jul 3 at 18:51
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Hi Phil, Thank you for your answer. I think something might have been wrong has your answer has not been sent entirely.
– Guillaume
Jul 2 at 8:22