.addOption and setValue duplicates option on origin select #124
Unanswered
martinbarilik
asked this question in
Q&A
Replies: 1 comment 8 replies
-
A couple of things going on in your code that I'll note below // addOption() wasn't designed to take an <option> element as an argument, it works but you're better off just passing data
getterSb.tomselect.addOption(new Option(cal, cal)); // instead, do: getterSb.tomselect.addOption({value:cal,text:cal});
getterSb.tomselect.refreshOptions(false);
// Tom Select has already created an <option> for cal at this point and now you're creating a duplicate
let newOption = new Option(cal, cal); // try newOption = getterSb.tomselect.getOption(cal) instead
newOption.dataset.calVal = selectedOption.dataset.calVals.split(',')[index]; |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I do not know if this is expected behavior, but if it is i can't use it.
The example shows my use-case. On a certain selectbox i need to append another SB with data attributes of origin. No idea if there is a cleaner way but this works partially for me. The problem appears when i am trying to get a data attribute of a selected appended option.
The selected option is appended automatically i think but it duplicates already added option by hand. So in time of need i have two options with the same value and automatically appended option is missing my data attributes.
Any way i can remove it ? I am open to any suggestion. These workarounds are pain for me :D
https://jsfiddle.net/mArtinko5MB/y1L845xa/78/
Beta Was this translation helpful? Give feedback.
All reactions