Skip to content

Commit

Permalink
Merge pull request #615 from matteodem/feature/autosuggest-no-docs-on…
Browse files Browse the repository at this point in the history
…-empty

Respect noDocumentsOnEmpty for autosuggest, fixes #566
  • Loading branch information
matteodem committed Jun 23, 2017
2 parents 82abff6 + 0846e9c commit 4829f47
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/easy:search/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'easy:search',
summary: "Easy-to-use search with Blaze Components (+ Elastic Search Support)",
version: "2.2.0",
version: "2.2.1",
git: "https://github.com/matteodem/meteor-easy-search.git",
documentation: "../../README.md"
});
Expand All @@ -12,7 +12,7 @@ Package.onUse(function(api) {
api.use([
'ecmascript',
'easysearch:core@2.2.0',
'easysearch:components@2.2.0',
'easysearch:components@2.2.1',
]);

api.export('EasySearch');
Expand Down
1 change: 1 addition & 0 deletions packages/easysearch:autosuggest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ You can pass in following parameters to the `EasySearch.Autosuggest` component.
* __labelField__: String that specifies the search result field to display, by default the first of index `fields`
* __changeConfiguration__: Function to change the configuration that is passed to selectize.
* __renderSuggestion__: String that specifies a custom template to render the autosuggest, by default `EasySearch_Autosuggest_DefaultRenderSuggestion`
* __noDocumentsOnEmpty__: Same as for EasySearch.Input

## How to install

Expand Down
7 changes: 4 additions & 3 deletions packages/easysearch:autosuggest/lib/autosuggest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Template } from 'meteor/templating'
import { Cursor } from 'meteor/easy:search'
import { SingleIndexComponent } from 'meteor/easysearch:components'

const getDataValue = (scope, val, defaultVal) => scope.getData()[val] || defaultVal
Expand All @@ -12,11 +13,11 @@ class AutosuggestComponent extends SingleIndexComponent
* @returns {Cursor}
*/
search(str) {
const methods = this.index.getComponentMethods(this.name)
if (!this.shouldShowDocuments(str)) return Cursor.emptyCursor

methods.search(str)
super.search(str)

return methods.getCursor()
return this.index.getComponentMethods(this.name).getCursor()
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/easysearch:autosuggest/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'easysearch:autosuggest',
summary: "Selectize Autosuggest Component for EasySearch",
version: "2.2.0",
version: "2.2.1",
git: "https://github.com/matteodem/meteor-easy-search.git",
documentation: 'README.md'
});
Expand Down
11 changes: 10 additions & 1 deletion packages/easysearch:components/lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ BaseComponent = class BaseComponent extends BlazeComponent {
return {};
}

/**
* @param {String} searchStr
*
* @returns {Boolean}
*/
shouldShowDocuments(searchStr) {
return !this.getData().noDocumentsOnEmpty || 0 < searchStr.length;
}

/**
* Search the component.
*
Expand All @@ -78,7 +87,7 @@ BaseComponent = class BaseComponent extends BlazeComponent {
search(searchString) {
check(searchString, String);

const showDocuments = !this.getData().noDocumentsOnEmpty || 0 < searchString.length;
const showDocuments = this.shouldShowDocuments(searchString);

this.eachIndex(function (index, name) {
index.getComponentDict(name).set('showDocuments', showDocuments);
Expand Down
2 changes: 1 addition & 1 deletion packages/easysearch:components/package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'easysearch:components',
summary: "Blaze Components for EasySearch",
version: "2.2.0",
version: "2.2.1",
git: "https://github.com/matteodem/meteor-easy-search.git",
documentation: 'README.md'
});
Expand Down

0 comments on commit 4829f47

Please sign in to comment.