Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TPantelConventus opened this issue Dec 6, 2022 · 6 comments
Labels
docs Improvements or additions to documentation

Comments

@TPantelConventus
Copy link

TPantelConventus commented Dec 6, 2022

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 :(

@TPantelConventus TPantelConventus 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 Dec 6, 2022
@weaverryan
Copy link
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
Copy link
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
Copy link
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.

@weaverryan weaverryan added the docs Improvements or additions to documentation label Dec 7, 2022
@carsonbot
Copy link

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

@carsonbot
Copy link

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

@TPantelConventus
Copy link
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 removed the Stalled label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants