Skip to content

[Autocomplete] tom_select_options closeAfterSelect losing search term after selecting two items #595

Open
@TPantelConventus

Description

@TPantelConventus

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:

autocomplete

edit: mardown and example.gif somehow do not work. I am sorry :(

Activity

changed the title [-][Autocomplete] tom_select_options closeAfterSelect losing search tearm after selecting two items[/-] [+][Autocomplete] tom_select_options closeAfterSelect losing search term after selecting two items[/+] on Dec 6, 2022
weaverryan

weaverryan commented on Dec 6, 2022

@weaverryan
Member

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 of onItemAdd to false, 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

TPantelConventus commented on Dec 7, 2022

@TPantelConventus
Author

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

weaverryan commented on Dec 7, 2022

@weaverryan
Member

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.

added
docsImprovements or additions to documentation
on Dec 7, 2022
carsonbot

carsonbot commented on Apr 25, 2024

@carsonbot

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

carsonbot

carsonbot commented on May 11, 2024

@carsonbot

Friendly reminder that this issue exists. If I don't hear anything I'll close this.

TPantelConventus

TPantelConventus commented on May 13, 2024

@TPantelConventus
Author

Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?

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

carsonbot commented on Nov 14, 2024

@carsonbot

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

TPantelConventus

TPantelConventus commented on Nov 14, 2024

@TPantelConventus
Author

Not yet resolved…

Also, the workaround does not seem to work anymore in newer versions

smnandre

smnandre commented on Nov 14, 2024

@smnandre
Member

@TPantelConventus would you like to work on a fix ? We'd love to guide you if needed!

carsonbot

carsonbot commented on May 15, 2025

@carsonbot

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

carsonbot

carsonbot commented on May 29, 2025

@carsonbot

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

carsonbot commented on Jun 12, 2025

@carsonbot

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @weaverryan@smnandre@Kocal@carsonbot@TPantelConventus

        Issue actions

          [Autocomplete] tom_select_options closeAfterSelect losing search term after selecting two items · Issue #595 · symfony/ux