Skip to content

select "change" event being triggered on initialization #163

@michelgallant

Description

@michelgallant

I was having issues with the select's "change" event being triggered during initialization. This was interfering with other functionality in my app.

I've made the following changes to the source to resolve this issue.

Starting at line 157

        // update count
        this._updateCount();
        that._filter.apply(this.availableContainer.find('input.search'), [that.availableList]);
  },
    _updateCount: function() {
        this.element.trigger('change');
        this.selectedContainer.find('span.count').text(this.count+" "+$.ui.multiselect.locale.itemsCount);
    },

I've changed it to

        // update count
        this._updateCount(false);
        that._filter.apply(this.availableContainer.find('input.search'), [that.availableList]);
  },
    _updateCount: function(trigger) {
        trigger = typeof trigger !== 'undefined' ? trigger : true;
        if(trigger)
            this.element.trigger('change');
        this.selectedContainer.find('span.count').text(this.count+" "+$.ui.multiselect.locale.itemsCount);
    },

This change leaves the count update in place, but avoids the extra initial trigger of the "change" event for the select.

I'm sure that there are better ways to implement this, but it works for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions