Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Template.foo.settings = function() {
- `sort`: (default `false`) Whether to sort the results before applying the limit. For good performance on large collections, this should be turned on only for server-side searches where an index can be used.
- `noMatchTemplate`: (optional) A template to display when nothing matches. This template can use the [reactive functions on the AutoComplete object](autocomplete-client.coffee) to display a specific message, or be [assigned mouse/keyboard events](http://docs.meteor.com/#eventmaps) for user interaction.
- `callback`: (optional) A function which is called when an item is selected with arguments `(doc, element)`, corresponding to the document of the selected item and the active input field.
- `inputDelay`: (optional) Delay in milliseconds to do the search after typing. Default: 500

Default matcher arguments: the default behavior is to create a regex against the field to be matched, which will be constructed using the arguments below.

Expand Down
13 changes: 12 additions & 1 deletion autocomplete-client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class @AutoComplete
constructor: (settings) ->
@limit = settings.limit || 5
@position = settings.position || "bottom"
@inputDelay = settings.inputDelay || 500

@rules = settings.rules
validateRule(rule) for rule in @rules
Expand Down Expand Up @@ -156,7 +157,17 @@ class @AutoComplete

# Did filter change?
if matches and @filter isnt matches[2]
@setFilter(matches[2])

# clear filter without waiting
if matches[2] is ''
@setFilter(matches[2])
else
clearTimeout @delayTimeout if @delayTimeout

@delayTimeout = setTimeout =>
@setFilter(matches[2])
, @inputDelay

breakLoop = true

break if breakLoop
Expand Down