select2 4.0 brings older list in suggestion with query method and minimumInputLength not taking effect

+1 vote
asked Aug 13, 2015 by dipal-mehta

I am in process of upgrading select2 version 3.5.1 to 4.0. I required to use query method for mandate.

There are two specific problem arises

  1. minimumInputLength is not taking effect
  2. When user focus searchbox, The past results are displayed with Searching.. is first item. (If I assign empty result then it resolves the problem but then it displays No results found message)

Please refer to my code snippet below.

var self = this, $view = $(view);

        $.fn.select2.amd.require(['select2/data/array', 'select2/utils', 'select2/data/minimumInputLength'], function (ArrayData, Utils, MinimumInputLength) {

            function CustomData($element, options) {
      , $element, options);
                this.options = options;

            Utils.Extend(CustomData, ArrayData);

            CustomData.prototype.query = function (params, callback) {
                //callback({ results: [] });
                q(ko.unwrap(self.qPromise)).then(function () {
                    var select2data = $.map(ko.unwrap(self.dataSource), function (obj) {
               = || obj.Id + obj.KeyDoc;
                        obj.text = obj.text || obj.Headline;
                        return obj;
                    callback({ results: select2data });

            // Decorate after the adapter is built
            Utils.Decorate(CustomData, MinimumInputLength);

                dataAdapter: CustomData,
                multiple: ko.unwrap(self.multiple),
                templateResult: ko.unwrap(self.formatFunc),
                escapeMarkup: function (markup) { return markup; },
                dropdownParent: $('.' + ko.unwrap(self.containerClass)),
                placeholder: ko.unwrap(self.placeHolderCaption),
                minimumInputLength: 1,
                allowClear: true


Every time I wish to assign new options in suggestion list (no cached no stored) Please suggest workaround.

Thanks in advanced

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter