I'm using select2 for create an unlimited option for select, which means whenever you type anything in select2 search box it can create an option related to what is the select for. Now I'm using the code below, which when type down it creates more than 1 option that I need it for.
Please help me with this.
$('#form-label-category-exterior').select2({
matcher: function matchExterior(params, data){
if ($.trim(params.term) === '') {
return data;
}
if (typeof data.text === 'undefined') {
return null;
}
if (data.text.indexOf(params.term) > -1) {
var modifiedData = $.extend({}, data, true);
return modifiedData;
} else{
var newOpt = new Option(params.term.toString() + '外装', params.term.toString() + '外装', true, true);
$('#form-label-category-exterior').append(newOpt)
}
return null;
}
})