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 29, 2016
1 parent 7e787cc commit 1aef761
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
18 changes: 18 additions & 0 deletions lib/ajax-chosen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions lib/ajax-chosen.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/ajax-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,25 @@ do ($ = jQuery) ->
@search_field = @element.next('.chosen-container')
.find(".search-field > input, .chosen-search > input")

@is_typing = false
@register_observers()

register_observers: ->
@search_field.on "compositionstart", (evt) =>
@is_typing = true
return
@search_field.on "compositionend", (evt) =>
@is_typing = 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 @is_typing
# This code will be executed every time the user types a letter
# into the input form that chosen has created

Expand Down Expand Up @@ -87,6 +96,7 @@ do ($ = jQuery) ->
# Create our own callback that will be executed when the ajax call is
# finished.
show_results: (data) ->
return if @is_typing
# Exit if the data we're given is invalid
return unless data?

Expand Down

0 comments on commit 1aef761

Please sign in to comment.