Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

support autocomplete with jQuery.Deferred-s as its source via Knockout

  • Loading branch information...
commit 7120c0d853a535e41dd7d6d4416fc2b1e90b5215 1 parent ea9ba3c
@dnagir authored
View
8 lib/assets/javascripts/knockout/bindings/autocomplete.js.coffee
@@ -39,7 +39,13 @@ ko.bindingHandlers.autocomplete =
options.source = (request, response) ->
src = ko.utils.unwrapObservable binding.source
- response filter(src, request.term, binding.label)
+ if src['fail']? and src['done']? and src['always']
+ # Looks like it's a jQuery.Deferred
+ src.done (data) -> response filter(data, request.term, binding.label)
+ src.fail -> response []
+ else
+ response filter(src, request.term, binding.label)
+
options.minLength = 2 unless options.minLength?
View
13 spec/javascripts/knockout/bindings/autocomplete_spec.js.coffee
@@ -41,6 +41,13 @@ describe "autocomplete", ->
search '1'
expect( itemsText() ).toBe '11'
+ it "should show labels for observable returning jQuery deferred", ->
+ prepare d = jQuery.Deferred()
+ search '1'
+ d.resolve ['11', '22']
+ expect( itemsText() ).toBe '11'
+
+
it "should show names for observable objects", ->
prepare [
{name: ko.observable('11'), id: 1}
@@ -55,9 +62,3 @@ describe "autocomplete", ->
search '2'
select '22'
expect( data.current() ).toBe obj
-
-
- describe "setting selected element", ->
- it "with array", -> expect('todo').toBe 'done'
- it "with observable array", -> expect('todo').toBe 'done'
- it "with jQuery AJAX object", -> expect('todo').toBe 'done'
Please sign in to comment.
Something went wrong with that request. Please try again.