Description
Hello everybody,
I think I noticed a little bug when using Autocomplete when 'multiple' is set to true in combination with the tom-select-option 'closeAfterSelect' set to false.
When you enter a serch term into the input field, you see a list with all matching items (as expected), but after you select two of them, the entered search term is missing and you have to reenter the search term.
First I thought that is because of something being strange, misconfigured or not up to date in the project where a customer reported that behaviour.
So I just started a brand-new Symfony 6.2 project only for the purpose of reproducing that behaviour and it is the same in the new project.
Here is the TestType form I created:
$builder
->add('test', ChoiceType::class, [
'choices' => $choices,
'label' => 'Choose number(s) please',
'multiple' => true,
'required' => false,
'autocomplete' => true,
'tom_select_options' => [
'closeAfterSelect' => false
],
'placeholder' => '',
])
->add('submit', SubmitType::class);
}
And here you can see what happens:
edit: mardown and example.gif somehow do not work. I am sorry :(
Activity
[-][Autocomplete] tom_select_options closeAfterSelect losing search tearm after selecting two items[/-][+][Autocomplete] tom_select_options closeAfterSelect losing search term after selecting two items[/+]weaverryan commentedon Dec 6, 2022
It looks like we manually clear the box after selecting an item: https://github.com/symfony/ux/blob/2.x/src/Autocomplete/assets/src/controller.ts#L85
If you set a
tom_select_options
key ofonItemAdd
tofalse
, does that fix it? That's just a workaround to try to determine if this is the cause.Why do we have that line? I wrote that code, but I have no idea why I included that. I borrowed the code from EasyAdmin, but they don't have this code. In many cases, it make sense: you type in a few characters, select an option, and now you want to start fresh again, without needing to delete the characters you already have. So, I'm a bit mixed on what to do.
TPantelConventus commentedon Dec 7, 2022
Thanks for the fast reply and I can confirm, that the workaround works for me.
I am also not sure, about what would be the better default behaviour.
In the app, where the users reported that behaviour to me, they obviously are often searching for items with similar names and do not want to re-enter the name after adding two items.
But I guess (after thinking about it for a while) in most use-cases the users want the default behaviour to be as it is right now.
So maybe leave it as it is, but document the option somewhere?
Anyway, thanks for your reply and offering a workaround.
weaverryan commentedon Dec 7, 2022
Thanks for confirming that! Yea, right now, I'm thinking we should document this. The current code is a little bit opinionated, but if it's easy to change it, I think that's ok. Unless we hear from a bunch of people that think removing the current behavior would be a better default.
carsonbot commentedon Apr 25, 2024
Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?
carsonbot commentedon May 11, 2024
Friendly reminder that this issue exists. If I don't hear anything I'll close this.
TPantelConventus commentedon May 13, 2024
Well, it is still not documented is the docs of Symfony UX Autocomplete , but nobody seems to care about the default behavior :)
But on the other hand, it still would be great for anybody who does not want the box cleared after an item is added, to directly be able how to get that in the docs.
carsonbot commentedon Nov 14, 2024
Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?
TPantelConventus commentedon Nov 14, 2024
Not yet resolved…
Also, the workaround does not seem to work anymore in newer versions
smnandre commentedon Nov 14, 2024
@TPantelConventus would you like to work on a fix ? We'd love to guide you if needed!
carsonbot commentedon May 15, 2025
Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?
carsonbot commentedon May 29, 2025
Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3
carsonbot commentedon Jun 12, 2025
Hey,
I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!