Reputation: 1730
I'm working on a project using Easyadmin
For a feature, I need to implement:
ChoiceField
with autocompletion configAssociationField
doesn't work since I need a non-mapped
fieldAny help !
Upvotes: 0
Views: 76
Reputation: 1730
After deep search and many tries, I got the right solution which is hooking into the autocomplete field natively and add some essential attributes.
Example: I have an entity called User and I'd like to have a ChoiceField with Users names List inside the HelloWorldCrudController:
$userUrl = $this->container->get(AdminUrlGenerator::class)
->set('autocompleteContext', array(
'crudControllerFqcn' => HelloWorldCrudController::class,
'propertyName' => 'garage',
'originatingPage' => Action::INDEX,
))
->setController(UserCrudController::class)
->setAction('autocomplete')
->set('page', 1);
$userChoiceField = ChoiceField::new('user', 'User')
->setFormType(EntityType::class)
->setFormTypeOption('class', User::class)
->autocomplete()
->setFormTypeOption('attr.data-ea-autocomplete-endpoint-url', $userUrl)
;
Upvotes: 0