You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
Reacted by Kewin Brandsma, Allen Fuller, Ruslan Stelmachenko, Dana Roberts, Ishmael Dos, Jonathan Allard, Elanor, François Gagné, Joseph Turner, tlkelley and 41 more
@KazutoDE Here is a working example using solution I suggested earlier. Note that the data attribute (in this case data-continent) would be gone from original option element after selectize is initialized, but it will be preserved on markup generated by selectize, so you can still access it.
$('.js-select').selectize({
onInitialize: function () {
var s = this;
s.revertSettings.$children.each(function () {
$.extend(s.options[this.value], $(this).data());
});
}
});
then inside the eventListener:
$('.js-select').change((e) => {
const value = $(e.currentTarget).val();
const options = $(e.currentTarget).data().selectize.options;
// There you have it
return options[value];
})
closing stale issues older than one year.
If this issue was closed in error please message the maintainers.
All issues must include a proper title, description, and examples.
It's a fair request. We're currently focused on getting the project actively maintained with security patches, dependency updates, processing the 120 opened PRs, etc.
This is a very valid enhancement and PRs are welcomed.
If anyone has bandwidth to work on this, open up a new PR against this issue and we can re-open it.
Looks like maybe #1194 addresses this too. We need to process all the PRs including their functionality, test coverage and all the usual suspects including performance. If you want to pull that PR down and check it too, the more the merrier!
Activity
MaherSaif commentedon Jan 13, 2014
+1
MaherSaif commentedon Jan 13, 2014
I've created a plugin to override -not extend- the function which changes the original select options.
Don't forget to load the plugin.
xak2000 commentedon Mar 19, 2014
Plugin is good but data-attributes in OPTIONs shouldn't disappear by default.
It is hurt for transparent selectizing of existing SELECT elements.
dylanbromby commentedon Mar 31, 2014
Yes! Selectize should be updated to allow for the preservation of custom attributes in each option.
vizcay commentedon May 17, 2014
+1
ryannealmes commentedon Jun 25, 2014
Would really appreciate a fix to this. Can't get plugin working.
jcomack commentedon Aug 25, 2014
+1
jontjs commentedon Aug 27, 2014
Agreed, selectize should retain data attributes
nexenator commentedon Sep 1, 2014
+1
dylanbromby commentedon Sep 1, 2014
I have no idea how I got CC'd on all the posts to this list, but I'd appreciate it if it stopped. Thanks!
On Sep 1, 2014, at 8:05 AM, Stephan Helbig notifications@github.com wrote:
arjan0307 commentedon Oct 20, 2014
+1
jensljungblad commentedon Dec 17, 2014
+1
telmogh commentedon Dec 17, 2014
+1
iamroi commentedon Dec 21, 2014
+1
iamroi commentedon Dec 21, 2014
This is working.
$(ele).selectize({
.....
dataAttr: 'data-extra', //default is data-data
.....
}
});
Add data-extra in every option as json encoded, Ex
option value="one" data-extra="{'test':'123'}"
option value="two" data-extra="{'test':'456'}"
Get the selectize instance using this, var selectize = $(ele)[0].selectize
Users selected options can be found here: selectize.items
Data attributes of all options can be found here: selectize.options
In our case it will be,
selectize.options['one'].test
selectize.options['two'].test
Let me know if this is working.
39 remaining items
smohadjer commentedon Sep 8, 2018
@KazutoDE Here is a working example using solution I suggested earlier. Note that the data attribute (in this case data-continent) would be gone from original option element after selectize is initialized, but it will be preserved on markup generated by selectize, so you can still access it.
http://sandbox.saeidmohadjer.com/selectize/
RudeySH commentedon Dec 15, 2018
#1058 by @dakuzen highlights an important issue when using the
$.extendworkaround by @indrimuska.naveed-ahmad commentedon Jan 9, 2019
@KazutoDE @WadeTheFade
Sample code which worked for me.
HTML markup
Init the selectize:
Then you can fetch the data attributes using:
No need to overrider the selectize's renderer or anything.
Younnah commentedon Feb 21, 2019
Hi @naveed-ahmad !
I tried your code, but it does not work at all for me...
When I write
$("select").data().selectize.options['1'].nameThe result is "undefined"
To hope to have an exit, I have to write
$("select").data().selectize.options["3"]and the result is
{text: "First", value: "3", $order: 1}I have only this option in my options array...
I tested many things but nothing that works to recover the data...
Thanks for your help !
naveed-ahmad commentedon Feb 21, 2019
@Younnah please see data attribute in my html,
data="{value:1, name: 'data 1'}"i'venameandvaluekeys.In your case keys are
text,value,$orderso
$("select").data().selectize.options['1'].nameSHOULD be undefined.Try
$("select").data().selectize.options['1'].textand value should be FirstYounnah commentedon Feb 22, 2019
Yes, I see, but I can not access the attribute "name" in the "data" ...
olucasu commentedon Jun 14, 2019
The way that worked for me
My only goal was to get the "selected" data-attr from the select
Get all data-attr
thanks to @indrimuska
then inside the eventListener:
Preserve custom HTML5 data attributes selectize/selectize.js#239
risadams commentedon Dec 1, 2020
closing stale issues older than one year.
If this issue was closed in error please message the maintainers.
All issues must include a proper title, description, and examples.
smohadjer commentedon Dec 1, 2020
@risadams I would have liked to see this shortcoming of Selectize to be fixed properly.
databyte commentedon Dec 1, 2020
It's a fair request. We're currently focused on getting the project actively maintained with security patches, dependency updates, processing the 120 opened PRs, etc.
This is a very valid enhancement and PRs are welcomed.
If anyone has bandwidth to work on this, open up a new PR against this issue and we can re-open it.
databyte commentedon Dec 1, 2020
Looks like maybe #1194 addresses this too. We need to process all the PRs including their functionality, test coverage and all the usual suspects including performance. If you want to pull that PR down and check it too, the more the merrier!
danieleklekoo commentedon Jun 6, 2022
selectize.txt
In attachment my implementation.
In order to see the changes search for the word "attributes".
Preserve custom HTML5 data attributes selectize/selectize.js#239