Skip to content

Commit

Permalink
Fix problem when input with Chinese input method
Browse files Browse the repository at this point in the history
Similar problem with:
Change event fires too many times when inputing Chinese characters
facebook/react#3926
  • Loading branch information
lingceng committed Apr 28, 2016
1 parent 7e787cc commit bad0229
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ajax-chosen.coffee
Expand Up @@ -29,16 +29,25 @@ 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

search_field_focused: (evt) ->
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

Expand Down

0 comments on commit bad0229

Please sign in to comment.