yanickrochon / jquery.uix.multiselect

Completely rewritten, multiselect widget with a more concise API
http://mind2soft.com/labs/jquery/multiselect/
MIT License
139 stars 62 forks source link

Header height is zero when searchField is false #98

Open oscarcosta opened 9 years ago

oscarcosta commented 9 years ago

Hello, I am implementing your widget in a project I am working, and it is very useful, thank! But I figured out that when the "searchField" option is set to false, the height of both headers is set to zero.

slovdahl commented 8 years ago

This seems to be caused by the _updateHeaders method not being called before _resize is invoked. I worked around it locally by inserting a second call to _resize in refresh like this:

        refresh: function(callback) {
            this._resize();  // just make sure we display the widget right without delay
            asyncFunction(function() {
                this.optionCache.cleanup();

                var opt, options = this.element[0].childNodes;

                for (var i=0, l1=options.length; i<l1; i++) {
                    opt = options[i];
                    if (opt.nodeType === 1) {
                        if (opt.tagName.toUpperCase() === 'OPTGROUP') {
                            var optGroup = $(opt).data('option-group') || (PRE_OPTGROUP + (this.optionGroupIndex++));
                            var grpOptions = opt.childNodes;

                            this.optionCache.prepareGroup($(opt), optGroup);

                            for (var j=0, l2=grpOptions.length; j<l2; j++) {
                                opt = grpOptions[j];
                                if (opt.nodeType === 1) {
                                    this.optionCache.prepareOption($(opt), optGroup);
                                }
                            }
                        } else {
                            this.optionCache.prepareOption($(opt));  // add to default group
                        }
                    }
                }

                this.optionCache.reIndex();
                // need to ensure the widget is correctly sized again, the header might have changed
                this._resize();

                if (this._searchField && this._searchField.is(':visible')) {
                    this._search(null, true);
                }

                if (callback) callback();
            }, 10, this);
        }

Not sure this is the best way of solving it, but at least it works for me.