I've been trying to attach a data-*
attribute in a Semantic UI dropdown option
but to no success (the data attributes are not being copied to the resulting dropdown options).
Here's the structure of my select
:
<select id='my-dropdown' name='department'>
<option value='1' data-wsg='something'>Department 1</option>
<option value='2' data-wsg='another'>Department 2</option>
. . .
<option value='n' data-wsg='custom data'>Department N</option>
</select>
$("#my-dropdown").dropdown({
allowAdditions: false,
fullTextSearch: true,
onHide: function() {
// Some codes.
},
onChange: function(value, text, choice) {
// Access the data-wsg attribute of the selected option.
}
});
I've been reading around a bit but all I saw regarding data attribute support was storing the settings in there. Not really what I need.
Hopefully someone has done something similar and let me know what the solution is.
Its not pretty, but you can use the details in the onChange to hunt down the data attribute. The functionality you are after was specifically rejected here - https://github.com/Semantic-Org/Semantic-UI/issues/931
onChange: function(value, text, choice) {
$(this).children('option[value=' + $(choice).data('value') + ']').data('wsg')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With