From bad0229378403ad4ce1d20231ced59d747b0fad8 Mon Sep 17 00:00:00 2001 From: lingceng Date: Thu, 28 Apr 2016 11:41:36 +0800 Subject: [PATCH] Fix problem when input with Chinese input method Similar problem with: Change event fires too many times when inputing Chinese characters https://github.com/facebook/react/issues/3926 --- src/ajax-chosen.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ajax-chosen.coffee b/src/ajax-chosen.coffee index d2e960b..64e040f 100644 --- a/src/ajax-chosen.coffee +++ b/src/ajax-chosen.coffee @@ -29,9 +29,17 @@ do ($ = jQuery) -> @search_field = @element.next('.chosen-container') .find(".search-field > input, .chosen-search > input") + @ignore_input = false @register_observers() register_observers: -> + @search_field.on "compositionstart", (evt) => + @ignore_input = true + return + @search_field.on "compositionend", (evt) => + @ignore_input = false + @update_list(evt) + return @search_field.keyup (evt) => @update_list(evt); return @search_field.focus (evt) => @search_field_focused(evt); return @@ -39,6 +47,7 @@ do ($ = jQuery) -> return @update_list(evt) if @options.minTermLength == 0 and @search_field.val().length == 0 update_list: (evt) -> + return if @ignore_input # This code will be executed every time the user types a letter # into the input form that chosen has created