How to customize messages from Select2?

Asked

Viewed 526 times

1

I want to remove messages from Select2:

  1. Searching;
  2. No Matches found;

Follow the code below:

Pagina Html

<input id="ajaxSecretaria" type="hidden" style="width:300px" />

Script:

$(function () {
    $('#ajaxSecretaria').select2(
    { minimumResultsForSearch: -1,
      ajax: {
        url: '@Url.Action("GetSecretarias", "Home")',
        dataType: 'json',
        data: function (term, page) {
            return { searchTerm: term };
        },
        results: function (data, page) {
                 return {results: data};
        }
    }
   });
});
  • 1

    Do you really want to customize or just translate?

  • I want the message not to appear.

2 answers

0

The title of the question speaks in "Customize", but in the comment it speaks in not appearing the message, so that being said, the codes below help in the part to hide and not to customize.

To remove Search vc you can use the following code:

$('select').select2({
    minimumResultsForSearch: -1
});

Already to remove No Matches found vc can use css:

.select2-no-results {
    display: none !important;
}

0

It is very simple to customize just put the instructions below in the call of your Javascript so:

formatNoMatches: function () { return "Pesquisa não encontrada"; },
formatInputTooShort: function (input, min) { return "Digite " + (min - input.length) + " caracteres para pesquisar"; },
formatSelectionTooBig: function (limit) { return "Selecione apenas 1 opção " + limit + " item" + (limit == 1 ? "" : "s"); },
formatLoadMore: function (pageNumber) { return "Carregando mais dados..."; },
formatSearching: function () { return "Pesquisando..."; }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.