From b7d4df1d7592a8c26cb192a31ea074d4125487f9 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 3 Dec 2014 14:55:17 -0200 Subject: [PATCH 1/2] added delay for search --- autocomplete-client.coffee | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/autocomplete-client.coffee b/autocomplete-client.coffee index 451f230..307927f 100644 --- a/autocomplete-client.coffee +++ b/autocomplete-client.coffee @@ -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 @@ -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 From 59935622bba1e876e22b553f6f78dcfc5bc3221e Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 3 Dec 2014 15:02:15 -0200 Subject: [PATCH 2/2] delay for search docs --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e56b7bd..3de245e 100644 --- a/README.md +++ b/README.md @@ -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.