How do you modify “No Results Found” language in Select2 v4.0

前端 未结 3 861
后悔当初
后悔当初 2020-12-24 04:55

I attempted to use the \"language.noMatches\" option when initiating Select2 and its throwing an undefined function? How do I go about modifying that bit of text? I would li

相关标签:
3条回答
  • 2020-12-24 05:19

    The option noMatches doesn't appear anywhere in the source code.

    The actual option is named noResults. The working version of your example is:

    $('#search-select').select2({
    
       ...
    
       "language": {
           "noResults": function(){
               return "No Results Found <a href='#' class='btn btn-danger'>Use it anyway</a>";
           }
       },
        escapeMarkup: function (markup) {
            return markup;
        }
    });

    You also need to override escapeMarkup, so the button appears correctly, as per this issue.

    0 讨论(0)
  • 2020-12-24 05:39

    Probably, you have to add the script for the language you want to use. Something like this:

    <script src="select2/js/i18n/pt-BR.js" type="text/javascript"></script>
    

    And then you can set the default language:

    $(".select2").select2({
      "language": "pt-BR"
    });
    
    0 讨论(0)
  • 2020-12-24 05:40

    The option for select 2.5 seems formatNoMatches:

    $('#search-select').select2({
      formatNoMatches: function () {
      return "No Results Found <a href='#' class='btn btn-danger'>Use it anyway</a>";
      }
    });
    
    0 讨论(0)
提交回复
热议问题