Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix reselecting option doesn't trigger 'change' event. #667

Closed
wants to merge 1 commit into from

6 participants

@ryanwilliams

This fixes a bug where the 'change' event isn't triggered if you reselect the same option after clearing it.

Reproduce the bug:
1. Have an instance with {allow_single_deselect: true} set.
2. Have some JS listening for the 'change' event on the 3. Select an option. (change event triggers) 4. Click the 'x' to clear selection. (change event triggers) 5. Select the same option again. (change event doesn't trigger)

@doits

if you're on it, you can also add the same fix when liszt:updated is triggered - see #672 for my fix in pure js (maybe calling val() is better than my proposal, I don't know atm)

@miguelm

+1 on this change, had to fork to get this fixed

@doits

I'm not sure: is this plugin dead (maybe author has no time to maintain it any more?). Would be nice to have a comment about this, because many fixes are waiting ...

@bojcan

Hi,

To fix it I added: this.current_value="" to the results_reset_cleanup() function. So it looks like that:

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

@stof
Collaborator

This should be fixed in the latest version of Chosen /cc @pfiller

@pfiller
Owner

Thanks @ryanwilliams. This did get fixed in a recent commit to chosen/master. I didn't see this pull request when I was looking for a fix -- sorry about that.

Thanks again.

@pfiller pfiller closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 0 deletions.
  1. +1 −0  coffee/chosen.jquery.coffee
  2. +1 −0  coffee/chosen.proto.coffee
View
1  coffee/chosen.jquery.coffee
@@ -322,6 +322,7 @@ class Chosen extends AbstractChosen
results_reset: ->
@form_field.options[0].selected = true
+ @current_value = @form_field_jq.val()
@selected_item.find("span").text @default_text
@selected_item.addClass("chzn-default") if not @is_multiple
this.show_search_field_default()
View
1  coffee/chosen.proto.coffee
@@ -314,6 +314,7 @@ class Chosen extends AbstractChosen
results_reset: ->
@form_field.options[0].selected = true
+ @current_value = @form_field.value
@selected_item.down("span").update(@default_text)
@selected_item.addClassName("chzn-default") if not @is_multiple
this.show_search_field_default()
Something went wrong with that request. Please try again.