diff --git a/coffee/chosen.proto.coffee b/coffee/chosen.proto.coffee index 7b3f5152a55..728332d4b1f 100644 --- a/coffee/chosen.proto.coffee +++ b/coffee/chosen.proto.coffee @@ -506,6 +506,7 @@ class @Chosen extends AbstractChosen @search_field.setStyle({'width': w + 'px'}) trigger_form_field_change: -> + Chosen.trigger(@form_field, 'input') Chosen.trigger(@form_field, 'change') @trigger: (element, eventType) -> diff --git a/spec/proto/events.spec.coffee b/spec/proto/events.spec.coffee new file mode 100644 index 00000000000..41d6494e865 --- /dev/null +++ b/spec/proto/events.spec.coffee @@ -0,0 +1,32 @@ +describe "Events", -> + it "chosen should fire the right events", -> + tmpl = " + + " + + div = new Element("div") + document.body.insert(div) + + div.update(tmpl) + select = div.down("select") + expect(select).toBeDefined() + new Chosen(select) + + event_sequence = [] + document.addEventListener 'input', -> event_sequence.push 'input' + document.addEventListener 'change', -> event_sequence.push 'change' + + container = div.down(".chosen-container") + Chosen.trigger(container, "mousedown") # open the drop + expect(container.hasClassName("chosen-container-active")).toBe true + + #select an item + Chosen.trigger(container.select(".active-result").last(), 'mouseup') + + expect(event_sequence).toEqual ['input', 'change'] + div.remove()