Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select "change" event being triggered on initialization #163

Open
michelgallant opened this issue Oct 22, 2014 · 1 comment
Open

select "change" event being triggered on initialization #163

michelgallant opened this issue Oct 22, 2014 · 1 comment

Comments

@michelgallant
Copy link

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.

@michelgallant
Copy link
Author

And...my code above was totally wrong, as it didn't trigger on "Add All" and "Remove All". I've settled on this to avoid triggering change on initialization, starting at line 158

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant