Selectize.js: Get raw data of selected object

Created on 1 Feb 2015  路  5Comments  路  Source: selectize/selectize.js

Hi, I want to know if is possible to implement some way to get raw data of the currently selected object, I mean a jQuery object with all the information of the item.

Currently there is getItem (), but it returns the jQuery element, not the data.

question

Most helpful comment

Do you mean the raw data? If so, give this a try:

var $select = $('select').selectize({ ... });
var selectize = $select[0].selectize;

var selected_objects = $.map(selectize.items, function(value) {
    return selectize.options[value];
});

All 5 comments

Do you mean the raw data? If so, give this a try:

var $select = $('select').selectize({ ... });
var selectize = $select[0].selectize;

var selected_objects = $.map(selectize.items, function(value) {
    return selectize.options[value];
});

It worked, thank you :)

This is how I get and use the "raw" data that is bound to the selected option;

$('#search').selectize({
    onItemAdd: function (value, $item) {    
        var data = this.options[value];
        if (data && data.Url) {
            window.location.href = data.Url;
        }
    }
});

An enhancement proposal is currently being considered at #1085

you can get all user events from onInitialize 馃憤

$('select').selectize({
         onInitialize: function (selectize) {
            selectize.on('change', function (value) {
                var elem = this.$input[0];
                console.log('on "change" event fired > ' + elem.id);
              });
            selectize.on('focus', function () {
                console.log('on "focus" event fired');
            });
            selectize.on('dropdown_open', function () {
                console.log('on "dropdown_open" event fired');
            });
        }
 }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

djthread picture djthread  路  5Comments

John-Fratila picture John-Fratila  路  4Comments

shoaibshakeel381 picture shoaibshakeel381  路  5Comments

tkrotoff picture tkrotoff  路  3Comments

aureole82 picture aureole82  路  3Comments