0
votes

I am trying to configure select2 plugin. It is working fine at the moment but when i try to disable case sensitivity then i am not able to figure it out.

Below are the codes.

<script type="text/javascript">
var lastResults = [];

$("#tags").select2({
    multiple: true,
    tags: true,
    placeholder: "Please enter keywords",
    tokenSeparators: [',', ' '],//[","],
    initSelection : function (element, callback) {
        var data = [];
        $(element.val().split(",")).each(function () {
            data.push({id: this, text: this});
        });
        callback(data);
    },
    ajax: {
        multiple: true,
        url: "fetch_keywords.php",
        dataType: 'json',

       data: function(term,page) {
                        return {
                            term: term
                           };
                    },
                    results: function(data,page) {
                         lastResults = data;
                          return {results: data};

                    }, 
    },
    maximumSelectionSize: 3,
    minimumInputLength: 3,
    maximumInputLength: 30,                       

createSearchChoice: function(term) {

    var text = term + (lastResults.some(function(r) {

      return r.text == term
    }) ? "" : " (new)");

    return {
      id: term,
      text: text
    };
  },
});

I have checked this question select2: Disable case-sensitive matches but i am not sure how can i use the same in my code.

If user entered test then it will return the match from database but if user enter Test then it create a new tag.

Thanks

1
I had another answer for disabled case sensitive, check it here.Tony Nguyen

1 Answers

1
votes

The only part of the question that I caught is comparing strings while ignoring the case of letters.

You can do it by converting both of the strings to lower or upper case before comparing.

For example lower(string) == lower(otherString).

Don't remember exactly how it is done in JavaScript.