Skip to content

Commit

Permalink
success callback is rebound on every key up.
Browse files Browse the repository at this point in the history
Should resolve issue meltingice#30
  • Loading branch information
jhanggi authored and jlavallee committed Feb 7, 2013
1 parent cd97514 commit efa8279
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/ajax-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@ do ($ = jQuery) ->
field = $(@)

# Default term key is `term`. Specify alternative in options.options.jsonTermKey
options.data = {} if not options.data?
options.data[options.jsonTermKey] = val
options.data = options.dataCallback(options.data) if options.dataCallback?
# Create a copy of options so options.success doesn't get overwritten
ajaxOptions = $.extend({}, options)
ajaxOptions.data = {} if not ajaxOptions.data?
ajaxOptions.data[options.jsonTermKey] = val
ajaxOptions.data = ajaxOptions.dataCallback(ajaxOptions.data) if ajaxOptions.dataCallback?

# If the user provided an ajax success callback, store it so we can
# call it after our bootstrapping is finished.
success = options.success
success = ajaxOptions.success

# Create our own callback that will be executed when the ajax call is
# finished.
options.success = (data) ->
ajaxOptions.success = (data) ->
# Exit if the data we're given is invalid
return if not data?

Expand Down Expand Up @@ -165,5 +167,5 @@ do ($ = jQuery) ->
# Execute the ajax call to search for autocomplete data with a timer
@timer = setTimeout ->
chosenXhr.abort() if chosenXhr
chosenXhr = $.ajax(options)
chosenXhr = $.ajax(ajaxOptions)
, options.afterTypeDelay

0 comments on commit efa8279

Please sign in to comment.