Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text "searching" in jquery select2

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).enter image description here

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
    });
like image 482
Surya prakash Patel Avatar asked Apr 24 '19 09:04

Surya prakash Patel


1 Answers

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.

like image 57
rohanc Avatar answered Oct 16 '22 12:10

rohanc