-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
createTag Method Breaking When Setting 'id' Anything Other Than 'term' #5023
Copy link
Copy link
Closed
Description
It may sound crazy, but whenever I implement the createTag method, I can't get the id to be anything other than the term. Here's the issue, I am performing a lookup in my database and if no result exists, I want to create a new tag, but I want to set the id to an empty GUID (00000000-0000-0000-0000-000000000000). Here's the code:
$('#VendorSelect').select2({
ajax: {
url: vendorAPI,
dataType: 'json',
delay: 250,
data: function (params) {
return {
partialName: params.term
};
},
processResults: function (data) {
return {
results: $.map(data, function (obj) {
return { id: obj.Value, text: obj.Text };
})
};
},
cache: false
},
minimumInputLength: 3,
tags: true,
placeholder: 'Select Vendor',
createTag: function (params) {
var term = $.trim(params.term);
if (term === '') {
return null;
}
return {
id: term, //'00000000-0000-0000-0000-000000000000',
text: term,
newTag: true
}
}
});
The code above works, but when I change the id: term to id: '00000000-0000-0000-0000-000000000000', the entire lookup/typeahead breaks.
Reactions are currently unavailable