-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Description
I wrote simply script based on select city example. I wanted dependent items list to be reloaded based on ajax query and next to select default value. This can be done by using onLoad method. But what i discovered is that dependent selectize object when using .load() method on it won't trigger onLoad event.
...
var xhr;
var select_state, $select_state;
var select_city, $select_city;
$select_state = $('#select-state').selectize({
onChange: function(value) {
if (!value.length) return;
console.log('test');
select_city.disable();
select_city.clearOptions();
select_city.load(function(callback) {
xhr && xhr.abort();
xhr = $.ajax({
url: 'http://www.corsproxy.com/api.sba.gov/geodata/primary_city_links_for_state_of/' + value + '.json',
success: function(results) {
select_city.enable();
callback(results);
},
error: function() {
callback();
}
})
});
}
});
$select_city = $('#select-city').selectize({
valueField: 'name',
labelField: 'name',
searchField: ['name'],
onLoad: function(value){
console.log(value);
}
});
select_city = $select_city[0].selectize;
select_state = $select_state[0].selectize;
select_city.disable();
...
If you read carefully I added to city example onLoad function definition to $select_city which print value to console.
This won't work.
Metadata
Metadata
Assignees
Labels
No labels