Skip to content

Commit

Permalink
Only clean up the deselect trigger for single selects (and don't call…
Browse files Browse the repository at this point in the history
… the rest of results_reset)

Fixes harvesthq#603, harvesthq#607, harvesthq#608, harvesthq#609, harvesthq#610
  • Loading branch information
Patrick Filler committed May 8, 2012
1 parent d8d450e commit b028f9e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
8 changes: 6 additions & 2 deletions chosen/chosen.jquery.js
Expand Up @@ -188,7 +188,7 @@ Copyright (c) 2011 by Harvest
};

AbstractChosen.prototype.results_update_field = function() {
this.results_reset();
if (!this.is_multiple) this.results_reset_cleanup();
this.result_clear_highlight();
this.result_single_selected = null;
return this.results_build();
Expand Down Expand Up @@ -698,11 +698,15 @@ Copyright (c) 2011 by Harvest
this.selected_item.find("span").text(this.default_text);
if (!this.is_multiple) this.selected_item.addClass("chzn-default");
this.show_search_field_default();
this.selected_item.find("abbr").remove();
this.results_reset_cleanup();
this.form_field_jq.trigger("change");
if (this.active_field) return this.results_hide();
};

Chosen.prototype.results_reset_cleanup = function() {
return this.selected_item.find("abbr").remove();
};

Chosen.prototype.result_select = function(evt) {
var high, high_id, item, position;
if (this.result_highlight) {
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.jquery.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions chosen/chosen.proto.js
Expand Up @@ -188,7 +188,7 @@ Copyright (c) 2011 by Harvest
};

AbstractChosen.prototype.results_update_field = function() {
this.results_reset();
if (!this.is_multiple) this.results_reset_cleanup();
this.result_clear_highlight();
this.result_single_selected = null;
return this.results_build();
Expand Down Expand Up @@ -690,11 +690,17 @@ Copyright (c) 2011 by Harvest
this.selected_item.down("span").update(this.default_text);
if (!this.is_multiple) this.selected_item.addClassName("chzn-default");
this.show_search_field_default();
this.selected_item.down("abbr").remove();
this.results_reset_cleanup();
if (typeof Event.simulate === 'function') this.form_field.simulate("change");
if (this.active_field) return this.results_hide();
};

Chosen.prototype.results_reset_cleanup = function() {
var deselect_trigger;
deselect_trigger = this.selected_item.down("abbr");
if (deselect_trigger) return deselect_trigger.remove();
};

Chosen.prototype.result_select = function(evt) {
var high, item, position;
if (this.result_highlight) {
Expand Down
2 changes: 1 addition & 1 deletion chosen/chosen.proto.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion coffee/chosen.jquery.coffee
Expand Up @@ -324,9 +324,12 @@ class Chosen extends AbstractChosen
@selected_item.find("span").text @default_text
@selected_item.addClass("chzn-default") if not @is_multiple
this.show_search_field_default()
@selected_item.find("abbr").remove()
this.results_reset_cleanup()
@form_field_jq.trigger "change"
this.results_hide() if @active_field

results_reset_cleanup: ->
@selected_item.find("abbr").remove()

result_select: (evt) ->
if @result_highlight
Expand Down
6 changes: 5 additions & 1 deletion coffee/chosen.proto.coffee
Expand Up @@ -316,9 +316,13 @@ class Chosen extends AbstractChosen
@selected_item.down("span").update(@default_text)
@selected_item.addClassName("chzn-default") if not @is_multiple
this.show_search_field_default()
@selected_item.down("abbr").remove()
this.results_reset_cleanup()
@form_field.simulate("change") if typeof Event.simulate is 'function'
this.results_hide() if @active_field

results_reset_cleanup: ->
deselect_trigger = @selected_item.down("abbr")
deselect_trigger.remove() if(deselect_trigger)

result_select: (evt) ->
if @result_highlight
Expand Down
2 changes: 1 addition & 1 deletion coffee/lib/abstract-chosen.coffee
Expand Up @@ -70,7 +70,7 @@ class AbstractChosen
""

results_update_field: ->
this.results_reset()
this.results_reset_cleanup() if not @is_multiple
this.result_clear_highlight()
@result_single_selected = null
this.results_build()
Expand Down

0 comments on commit b028f9e

Please sign in to comment.