I have this code.
$customer = $(".customer").selectize({
valueField: 'builder',
labelField: 'builder',
searchField: 'builder',
openOnFocus: true,
createOnBlur: true,
maxItems: 1,
create: function (input) {
newOption = true;
return {
builder: input,
value: input,
text: input,
};
},
render: {
option: function (item) {
return (
"<div class='selectize-item'>" +item.builder+ "</div>"
);
},
},
load: function (query, callback) {
if (!query.length) {
return callback();
}
$.ajax({
url: "/api/xxx/xxx",
type: "GET",
dataType: "json",
data: {...},
error: function () {
callback();
},
success: function (res) {
callback(res);
},
});
},
});
I’ve used selectize to a dropdown that allows users to add their own option. I believe this can be done through the create method.
My question here is how can I know that the user has added a new option instead of selecting the options that were pre-loaded. I am planning that if the user has added a new option I will make my variable newOption into true, while if the user has selected to the options that were pre-loaded, newOption will be false.
When I say “pre-loaded”, this is an option that has been loaded through Ajax. You can see it on my load method that the dropdown options are loaded through Ajax.
Any help is greatly appreciated!



