-
Notifications
You must be signed in to change notification settings - Fork 601
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
Passing attributes from html data #182
Comments
You can't currently add custom properties via HTML but as of version 2.8.6, you can pass custom properties to items/choices via JS . Will re-open this if more people request this. |
It would be nice if the plugin allowed passing additional classes at least. <select class="c-select c-select--dark">....</select> after initialised with Edit: ...and actually extending it to at least some other basic/popular functionality like placeholders and maybe some other options would rock. Edit 2: I guess sending other params via a data attribute yourself is simple enough, but passing classes would still be useful for different variations/skins. My solution for placeholders: <select
class="c-select"
data-select-options='{"placeholderValue": "Select payment method"}'>
...
</select> const selectWithOpts = document.querySelector('.c-select[data-select-options]');
const selectOptions = selectWithOpts && selectWithOpts.getAttribute('data-select-options');
new Choices(
'.c-select[data-select-options]',
JSON.parse(selectOptions),
); |
It is very necessary and convenient to pass data-attributes. Please, add it. |
@jshjohnson Can this one be reopened? It would like to have HTML data attribute support. |
This is a must, especially if you are working with Livewire, PHP and Alpine.JS. It's a lot cleaner, I might push to this repo. |
Is there any support for
data
attributes from HTML? I want to pass the values on specificselect
item and only to it. Can't do it in JS by passingid
or other attribute b/c it must me reusable element. And to all, I'm passing default values or same classes too. Can I in another way pass element 2 times or in 2 different ways?The best way is to pass
data
attributes toselect
and when callingChoices
with default values add this custom one if existing and pass as parameters too.If want some code can prepare something or show concept
The text was updated successfully, but these errors were encountered: