Permalink
Browse files

Track current value to prevent erroneous change events.

  • Loading branch information...
1 parent a722f5e commit 3b3636e2e12f6fbdd5a225f4aeb2162048952d31 @pfiller pfiller committed May 25, 2012
@@ -303,6 +303,7 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.setup = function() {
this.form_field_jq = $(this.form_field);
+ this.current_value = this.form_field_jq.val();
return this.is_rtl = this.form_field_jq.hasClass("chzn-rtl");
};
@@ -735,9 +736,13 @@ Copyright (c) 2011 by Harvest
}
if (!(evt.metaKey && this.is_multiple)) this.results_hide();
this.search_field.val("");
- this.form_field_jq.trigger("change", {
- 'selected': this.form_field.options[item.options_index].value
- });
+ if (this.is_multiple || this.form_field_jq.val() !== this.current_value) {
+ this.form_field_jq.trigger("change", {
+ 'selected': this.form_field.options[item.options_index].value
+ });
+ }
+ this.current_value = this.form_field_jq.val();
+ console.log(this.current_value);
@stof
stof May 25, 2012 Collaborator

why is there a console.log call in the code ?

@pfiller
pfiller May 25, 2012 Collaborator

Good catch. 5a0a7eb

return this.search_field_scale();
}
};
Oops, something went wrong.
@@ -285,6 +285,7 @@ Copyright (c) 2011 by Harvest
}
Chosen.prototype.setup = function() {
+ this.current_value = this.form_field.value;
return this.is_rtl = this.form_field.hasClassName("chzn-rtl");
};
@@ -728,9 +729,11 @@ Copyright (c) 2011 by Harvest
}
if (!(evt.metaKey && this.is_multiple)) this.results_hide();
this.search_field.value = "";
- if (typeof Event.simulate === 'function') {
+ if (typeof Event.simulate === 'function' && (this.is_multiple || this.form_field.value !== this.current_value)) {
this.form_field.simulate("change");
}
+ this.current_value = this.form_field.value;
+ console.log(this.current_value);
return this.search_field_scale();
}
};
Oops, something went wrong.
@@ -19,6 +19,7 @@ class Chosen extends AbstractChosen
setup: ->
@form_field_jq = $ @form_field
+ @current_value = @form_field_jq.val()
@is_rtl = @form_field_jq.hasClass "chzn-rtl"
finish_setup: ->
@@ -363,7 +364,8 @@ class Chosen extends AbstractChosen
@search_field.val ""
- @form_field_jq.trigger "change", {'selected': @form_field.options[item.options_index].value}
+ @form_field_jq.trigger "change", {'selected': @form_field.options[item.options_index].value} if @is_multiple || @form_field_jq.val() != @current_value
+ @current_value = @form_field_jq.val()
this.search_field_scale()
result_activate: (el) ->
@@ -7,6 +7,7 @@ root = this
class Chosen extends AbstractChosen
setup: ->
+ @current_value = @form_field.value
@is_rtl = @form_field.hasClassName "chzn-rtl"
finish_setup: ->
@@ -353,8 +354,10 @@ class Chosen extends AbstractChosen
this.results_hide() unless evt.metaKey and @is_multiple
@search_field.value = ""
-
- @form_field.simulate("change") if typeof Event.simulate is 'function'
+
+ @form_field.simulate("change") if typeof Event.simulate is 'function' && (@is_multiple || @form_field.value != @current_value)
+ @current_value = @form_field.value
+
this.search_field_scale()
result_activate: (el) ->

0 comments on commit 3b3636e

Please sign in to comment.