Selectize.js: Pass item selected object to onItemAdd

Created on 10 Jan 2014  路  14Comments  路  Source: selectize/selectize.js

Now:

/**
  value - selected value
  $item - selected option DOM
*/
onItemAdd(value, $item)

Expected:

/**
  value - selected value
  $item - selected option DOM
  item - selected object data with all data pass bt create/load 
*/
onItemAdd(value, $item, item)

Workaround:
selectize.js, change line:
-- self.trigger('item_add', value, $item);
++ self.trigger('item_add', value, $item, $option);

in your code by $option we can pass some extra data but access is complex eg.

 onItemAdd: function(value, item, option) {
                    var $cell = $($(this)[0].$wrapper).parent(), 
                        $addressInput = $cell.find('.address'),
                        $option = $(option),
                        $address = $option.find('.address');
//....

Most helpful comment

As far as I can tell all current options can be accessed through this.options, and so to get the selected option the following worked for me:

...
onItemAdd: function(value, $item) {
    console.log(this.options[value]);
},

All 14 comments

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

As far as I can tell all current options can be accessed through this.options, and so to get the selected option the following worked for me:

...
onItemAdd: function(value, $item) {
    console.log(this.options[value]);
},

@leifdenby saved my day!

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndyBean picture AndyBean  路  15Comments

arathael picture arathael  路  33Comments

Saeven picture Saeven  路  15Comments

Landish picture Landish  路  17Comments

eliashdezr picture eliashdezr  路  41Comments