chosen does not update 'current_value' on 'liszt:updated' #672

Closed
doits opened this Issue Jun 8, 2012 · 8 comments

Projects

None yet

7 participants

doits commented Jun 8, 2012

when the selected item of the original list is changed programatically and chosen-update is triggered, it does not get the new value:

<select id="chosen_select">
    <option selected="">first</option>
    <option id="second">second</option>
</select>

$("#chosen_select").chosen()
$("#chosen_select").on 'change', ->
    alert 'changed'

$('#second').prop 'selected', true
$('#chosen_select').trigger 'liszt:updated'

When you change the select to "first" with mouse, the change is not triggered.

I triggered it down to AbstractChosen.prototype.results_update_field, where simply setting this.current_value = this.form_field.value is enough - at least in the case of !this.is_multiple. What to happen when it is multiple, I don't know.

doits commented Jun 8, 2012

same is true when clicking on the X to deselect a choice with allow_single_deselect. To fix:

Chosen.prototype.results_reset = function() {
    ...
    if (!this.is_multiple) {
        this.selected_item.addClass("chzn-default");
        this.current_value = null;
    }
    ...
}

(since I test it in live JS I cannot provide the right CoffeeScript, sry - but changes are easy and should be trivial to spot in coffee)

Cool Im also a victim for this issue. Merge of pull request would be very welcome!

Good job!

Thanks

Thanks for this heads up, just what I was looking for.

JDeuce commented Jul 31, 2012

+1 on this, just manually patched with above fix and it resolved the issue I was having

tonyhb commented Sep 5, 2012

+1 on this, also had to patch

Collaborator
stof commented Sep 5, 2012

@dynamism have you tried with the latest version of Chosen ? A fix related to resetting the current value was merged 2 days ago

tonyhb commented Sep 5, 2012

Ah no, hadn't done that actually! Good to know :)
On 5 Sep 2012 11:55, "Christophe Coevoet" notifications@github.com wrote:

@dynamism https://github.com/dynamism have you tried with the latest
version of Chosen ? A fix related to resetting the current value was merged
2 days ago


Reply to this email directly or view it on GitHubhttps://github.com/harvesthq/chosen/issues/672#issuecomment-8294317.

Contributor
pfiller commented Sep 5, 2012

Yep - this is fixed in master so go ahead and grab the latest version. Sorry I missed this thread when I was closing related issues.

@pfiller pfiller closed this Sep 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment