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

triggerChange() gets called when the previous value has been selected again #33

Open
lmeurs opened this issue Mar 24, 2015 · 0 comments

Comments

@lmeurs
Copy link

lmeurs commented Mar 24, 2015

After openening a select one might want to close it by clicking the previously selected option. Though the value has not changed, Select.prototype.pickOption() still calls this.triggerChange() which causes our AJAX form to submit.

We could add a valueHasChanged flag and check this before calling this.triggerChange():

Select.prototype.pickOption = function(option, close) {
  var _this = this, valueHasChanged;
  if (close == null) {
    close = true;
  }
  valueHasChanged = this.value !== option.getAttribute('data-value');
  this.value = this.select.value = option.getAttribute('data-value');
  if (valueHasChanged) {
    this.triggerChange();
  }
  if (close) {
    return setTimeout(function() {
      _this.close();
      return _this.target.focus();
    });
  }
};
geekjuice pushed a commit that referenced this issue Jun 26, 2015
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