I am creating this Select2 combo using an external ajax jsonp datasource. I am struggling to find a way, using the latest 4.0 version, to allow user input into the field, even when there is an Ajax error. The best case scenario would be only allowing when there is an error, but would be ok either way.
I've tried to add a createTag function, tags:true, ajax.error function returning an empty result array, but neither help much.
$('#location').select2({
ajax: {
url: '//geoservice.to',
dataType: 'jsonp',
quietMillis: 250,
data: function (params) {
return {
q: params.term.toLowerCase(),
maxRows: 15,
startRow: (params.page || 0) * 15
};
},
error: function(params) {
params.then({}); // wanted to result no results on error and //let what user searched for to be inserted
},
processResults: function (data, params) {
params.page = params.page || 1;
return {
results: $.map(data.results, resultMapper),
pagination: {
more: (params.page * 15) < data.totalResultsCount
}
};
},
cache: true
},
minimumInputLength: 2,
allowClear : true,
tags: true, // ? needed?
createTag: // need it?
placeholder : 'Select a city'
})
Any thoughts?