In one page I have multiple selectize select with same name. I can`t populate the selectize with value from database. (At the beginning the select is empty because I have 40k values in database).
This is a javascript code: (work only when I search in select)
$('.nume_medicament').selectize({
valueField: 'nume_medicament',
labelField: 'nume_medicament',
searchField: 'nume_medicament',
options: [],
create: false,
render: {
option: function(item, escape) {
return '<option datacod="'+item.cod_medicament+'" value="'+item.id_medicament+'">'+item.nume_medicament+'</option>';
},
},
load: function(query, callback) {
if (!query.length) return callback();
$.ajax({
url: site_url + "medicmed/get_medicamente_by_search",
type: 'GET',
dataType: 'json',
data: {
name: query,
},
error: function() {
callback();
},
success: function(res) {
callback(res);
}
});
},
});
And this is html file:
<select name="nume_medicament" class="nume_medicament checkmed selectizedefault">
<option selected datacod="<?=$pm->cod_medicament?>" value="<?=$pm->id_medicament?>"><?=$pm->nume_medicament?></option>
</select>
A want to assign the option when I enter in the page.
Thank you!!