[Autocomplete + Live Component] Validation issue when using an autocomplete field in a live component
Hello ! I've found an issue when using an autocomplete field in a live component. The autocomplete field is configured with these options :
$builder
->add('emails', ChoiceType::class, [
'multiple' => true,
'autocomplete' => true,
'tom_select_options' => [
'create' => true,
],
'label' => 'Email of the team members',
'attr' => [
'placeholder' => 'Email of the team members',
]
])
;
But, when I add a choice, I have a 422 error in javascript console and a form errror with value "The selected choice is invalid."
You can reproduce the issue with this simple project
PHP Version : 8.2 Symfony version : 7.0 Asset Mapper version : 7.0 Symfony UX Version : 2.13.3
There are some known issues with Autocomplete + Live + multiple https://symfony.com/bundles/ux-autocomplete/current/index.html#known-issue-when-using-with-live-component
I’ll take a look later today but i dont want to give you too much hope :/
This is just a shortcoming of the autocomplete library, or rather a missing feature. You can set the create option to allow creating on the frontend, but there's no mechanism to handle that on the backend - i.e. by persisting a new item to the database.