selectize.js icon indicating copy to clipboard operation
selectize.js copied to clipboard

How to get this element on event

Open emharis opened this issue 11 years ago • 5 comments

how to get THIS element on event , example: on event "onItemAdd" I want to get this select box object , and from the object I want get data on it.

//jquery var eventHandler = function (item) { return function () { //how can I get the cbselect object and get data hiddenname here

    };
};

$('#cbselect').selectize({ create: function (input, callback) { return { value: input, text: input }; onItemAdd : eventHandler('onItemAdd') });

emharis avatar Sep 01 '15 23:09 emharis

The selectize() function returns the corresponding object, so you can get the list of options from it. How you access this value depends on your code structure, of course.

PhiLhoSoft avatar Sep 14 '15 08:09 PhiLhoSoft

Something like the following should do the trick:

var selectize = $('#cbselect').get(0).selectize;
var current = selectize.getValue(); 
var option = selectize.options[ current ];
var mydata = option['hiddenname'];

That's assuming a single-select; for a multi-select getValue() will return an array of values which you will need to iterate over.

mcavalletto avatar Jan 22 '16 17:01 mcavalletto

@mcavalletto thanks, it works fine

AhmedHdeawy avatar Jan 10 '18 09:01 AhmedHdeawy

@mcavalletto I have multiple selectized combo boxes. Is it possible to get the corresponding element in the event and set the selectize value?

pmfederico avatar Apr 05 '19 13:04 pmfederico

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Jan 07 '21 02:01 github-actions[bot]