Unable to query original select
When you select an option with selectize it changes the original select component adding an option with the selected value
for (i = 0, n = this.items.length; i < n; i++) {
options.push('<option value="' + htmlEntities(this.items[i]) + '" selected="selected"></option>');
}
I think the option component should reflect exactly how the original option was (including the label) so the user can query the select component and get the label and wherever data he wants from it.
The reasoning behind not keeping the DOM up to date with the non-selected options had to do with performance. In some cases, it could lead to managing thousands of <option> tags—which could add some sluggishness without much advantage added. Furthermore, it complicates the code / makes the library larger. Could you provide a use case that shows how reading options from the DOM after-the-fact is useful?
@brianreavis since I've not had time to have a look at it, I assume there is no reason why the plugin architecture couldn't handle this?
I agree that it's not necessary to add all options to the selected element. Only the selected one is fine, but my problem is that even the selected option does not fully reflect the dom of the original option. It just creates an option element with the same value as the original option.
In my use case I needed to have access to the LABEL of the selected option. I think that will not affect performance or code readability. Since it's a minor thing I'll try to implement myself and submit a pull request when I have time.
Thanks :)
@brianreavis
Could you provide a use case that shows how reading options from the DOM after-the-fact is useful?
My problem: I have added data-* attributes in option tags and using these attributes for calculate different things in JS later. But I can't use them because selectize.js remove these attributes. So, I think selectize.js should respect data-* attributes in options. Also, I think this is will be appropriate solution for @marcioaguiar problem.
Could you please support data-* attributes in option tags in next selectize.js version?
Thanks
Could you provide a use case that shows how reading options from the DOM after-the-fact is useful?
@brianreavis I need to display a live preview of the options selected. For this I need the original innerText of the option. From what I can tell, the selectize callbacks (specifically onChange) only returns value. In my case the value of the option is just an id.
+1 for this issue. dup: https://github.com/brianreavis/selectize.js/issues/598
@brianreavis We're currently using select2 and attempting to move selectize breaks our integration test since they interact with elements in the dom.
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.