Skip to content

Implementation of adding data attribute for appended option element? #109

Discussion options

You must be logged in to vote

Finally did it. If there is a better way to do it, please let me know

			options.onItemAdd = function (value, $item) { // to remove old options added
				this.input.querySelectorAll('option:not([value=""])').forEach(option => {
					option.remove();
				});
			}

			options.onChange = function (value) {
				let tsOption = this.options[this.items[0]];

				let desirableOption = this.input.querySelector(`option[value="${this.items[0]}"]`);
				desirableOption.dataset.whatever = tsOption.whatever;
			}

                        new TomSelect(select, options);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by martinbarilik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant