如何在运行时设置新添加选项的值。目前在值中选择选项名称。我正在使用下面的代码。
$(document).ready(function () {
$('#dept').selectize({
create: true, sortField: 'text'
});
});
答案 0 :(得分:0)
使用Selectize API中提供的createItem
和updateOption
方法添加新选项并自定义其值。查看this fiddle.
答案 1 :(得分:0)
Its working for me like
$(function(){
$('#desig').selectize({
create:function (input, callback){
$.ajax({
url: "<?php echo $this->url(null, array('controller' => 'employee-detail', 'action' => 'add-new-desig-ajax'));?>",
type: 'POST',
data:{'designation':input},
success: function (result) {
if (result) {
// console.log('sdfasf',result);
callback({ value: result.id, text: input });
}
}
});
}
});
});
I have taken help from here
https://stackoverflow.com/questions/24366365/creating-an-item-if-not-already-exists-in-selectize-js-select-box-and-ajax-updat/46096111#46096111