Home > Mobile >  Multi-Select template for custom forms
Multi-Select template for custom forms

Time:11-09

In my EasyAdmin 3 application I have build a custom form (with Symfony and Doctrine) with a multi-select field. Since it is a custom form I do not get the nice multi-select dropdown theme that EasyAdmin normally provides:

enter image description here

With earlier EasyAdmin versions it was possible to just add the "select2" classes to the field. But it seems to work different now in EasyAdmin 3. Is there a way to add the multi-select theme of EasyAdmin to a custom form field?

My use case is: I have an AccountEntity which has a relation to a UserEntity and a ServiceEntity. I want to have the possibility to add multiple Accounts for a User with different Services. Since an Account has only one Service I can not use the standard Account Creation Form. I need the Service field to be a multi-select. So my current idea is to built a custom form with Symfony and Doctrine and have my own logic to create the Accounts. Maybe there is a better way to build this functionality with built-in features of EasyAdmin 3?

CodePudding user response:

Actually I found the answer to my problem:

You have to add the following attribute to the form field:

data-ea-widget="ea-autocomplete"

Also EasyAdmin3 is using https://tom-select.js.org/ instead of Select2 like in the previous versions.

  • Related