I am using select2 with ajax option, and when ajax runs, a text "searching" appearing until ajax get success. I want to change this text(see in attached image
).
My code is:(reference from https://select2.org)
$("#employee_id").select2({
ajax: {
url: "get_store_data.php?type=employee_data",
dataType: 'json',
delay: 250,
data: function (params) {
return {
phrase: params.term, // search term,
store_name: jQuery("#store_name").val(),
page: 1
};
},
processResults: function (data, params) {
// console.log(data);
params.page = params.page || 1;
return {
results: data.map(function(item) {
return {
id: item.name,
text: item.name
};
}),
pagination: {
more: 0
}
};
},
placeholder: 'Search for a member id',
cache: true
},
escapeMarkup: function (markup) { return markup; },
minimumInputLength: 1
});
If understand you correctly, you want to change the text that appears whilst you are waiting (for the Ajax to complete. That text disappears after it completes. By default the text is "Searching...". The code below will change it to "Something else...".
$("#employee_id").select2({
language: {
searching: function() {
return "Something else...";
}
},
ajax: {
url: "get_store_data.php?type=employee_data",
// etc.
}
}
See the Select2 v4 documentation concerning Translation objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With