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] Don't want a clear button #379

Open
maartendekeizer opened this issue Jul 5, 2022 · 4 comments · May be fixed by #401
Open

[Autocomplete] Don't want a clear button #379

maartendekeizer opened this issue Jul 5, 2022 · 4 comments · May be fixed by #401

Comments

@maartendekeizer
Copy link
Contributor

A clear button is automaticly added when the autocomplete is not disabled and not multiple:

        if (!this.formElement.disabled && !isMultiple) {
            plugins.clear_button = { title: '' };
        }

How can we always disable the clear_button plugin?

Already tried, but that will result in a error

{{ stimulus_controller('symfony/ux-autocomplete/autocomplete', {tom_select_options: {maxItems: 1, plugins: {clear_button: null}}})}}
@weaverryan
Copy link
Member

Yea, we should make this configurable somehow. We could do it as you suggested (maybe changing it to clear_button: false instead of null) or we could add a new option as a "sibling" to tom_select_options:

{{ stimulus_controller('symfony/ux-autocomplete/autocomplete', {
    plugins: { remove_button: { title: '' } }
})  }}

The idea is that IF you supply plugins, then YOU become 100% in control of the plugins enabled: we would no longer attempt to add any default plugins for you - i.e. none of this code would run -

if (!this.formElement.disabled && !isMultiple) {
plugins.clear_button = { title: '' };
}
if (isMultiple) {
plugins.remove_button = { title: '' };
}
if (this.urlValue) {
plugins.virtual_scroll = {};
}

I think that's the best option - PR welcome :)

@maartendekeizer
Copy link
Contributor Author

@weaverryan That will break implementations where extra (non default activated plugins) are added. That is not a problem?

@weaverryan
Copy link
Member

Hmm, I'm not sure I understand the problem you're thinking of. My thinking is that if you pass this plugins option, then we would start the configuration with plugins = {}. If you are currently adding additional plugins via { tom_select_options: { plugins: { ... }} }, that would still work fine: your plugins would override the empty {}. Or is there some situation that I'm not seeing?

@maartendekeizer
Copy link
Contributor Author

@weaverryan I agree with your solution and made a PR for that.
The issue I mentioned was about backwards compatibility. Implementations that have defined the plugins property with the drag_drop plugin will currently have the drag drop plugin and the default plugins. After this change they only have the drag and drop plugin because the default plugins are not explicitly defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants