From 0506eee2a6e139f26a170ef6e1581c12760500fd Mon Sep 17 00:00:00 2001 From: Felix Sanz Date: Sat, 5 Mar 2016 22:20:29 +0100 Subject: [PATCH 1/3] Added minChars parameter Pass minChars: X to start fetching results only when the query length is equal or higher --- vue-typeahead.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vue-typeahead.js b/vue-typeahead.js index 6bbc2a0..5f3c493 100644 --- a/vue-typeahead.js +++ b/vue-typeahead.js @@ -19,6 +19,10 @@ export default { this.warn('`src` property') } + if (this.minChars && this.minChars !== parseInt(this.minChars, 10)) { + this.warn('`minChars` method to be an integer') + } + if (! this.onHit) { this.warn('`onHit` method') } @@ -49,6 +53,10 @@ export default { return } + if (this.minChars && this.query.length <= this.minChars) { + return + } + this.loading = true this.$http.get(this.src, Object.assign({q:this.query}, this.data)) From 85505bbfedb7dcbb25fa818f576b843b4461dc7e Mon Sep 17 00:00:00 2001 From: Felix Sanz Date: Sat, 5 Mar 2016 22:21:34 +0100 Subject: [PATCH 2/3] Updated docs for minChars --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6085f61..632e591 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Vue.component('typeahead', { src: '...', // required data: {}, // optional limit: 5, // optional + minChars: 3, // optional onHit (item) { // required // ... }, From e46375f47a8982c8e989627ea4d9738107832f83 Mon Sep 17 00:00:00 2001 From: Felix Sanz Date: Sat, 5 Mar 2016 22:22:25 +0100 Subject: [PATCH 3/3] Added check for this.limit --- vue-typeahead.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vue-typeahead.js b/vue-typeahead.js index 5f3c493..5071571 100644 --- a/vue-typeahead.js +++ b/vue-typeahead.js @@ -19,6 +19,10 @@ export default { this.warn('`src` property') } + if (this.limit && this.limit !== parseInt(this.limit, 10)) { + this.warn('`limit` method to be an integer') + } + if (this.minChars && this.minChars !== parseInt(this.minChars, 10)) { this.warn('`minChars` method to be an integer') }