Skip to content

Commit 4829f47

Browse files
authored
Merge pull request #615 from matteodem/feature/autosuggest-no-docs-on-empty
Respect noDocumentsOnEmpty for autosuggest, fixes #566
2 parents 82abff6 + 0846e9c commit 4829f47

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

packages/easy:search/package.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package.describe({
22
name: 'easy:search',
33
summary: "Easy-to-use search with Blaze Components (+ Elastic Search Support)",
4-
version: "2.2.0",
4+
version: "2.2.1",
55
git: "https://github.com/matteodem/meteor-easy-search.git",
66
documentation: "../../README.md"
77
});
@@ -12,7 +12,7 @@ Package.onUse(function(api) {
1212
api.use([
1313
'ecmascript',
1414
'easysearch:[email protected]',
15-
'easysearch:[email protected].0',
15+
'easysearch:[email protected].1',
1616
]);
1717

1818
api.export('EasySearch');

packages/easysearch:autosuggest/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ You can pass in following parameters to the `EasySearch.Autosuggest` component.
1818
* __labelField__: String that specifies the search result field to display, by default the first of index `fields`
1919
* __changeConfiguration__: Function to change the configuration that is passed to selectize.
2020
* __renderSuggestion__: String that specifies a custom template to render the autosuggest, by default `EasySearch_Autosuggest_DefaultRenderSuggestion`
21+
* __noDocumentsOnEmpty__: Same as for EasySearch.Input
2122

2223
## How to install
2324

packages/easysearch:autosuggest/lib/autosuggest.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Template } from 'meteor/templating'
2+
import { Cursor } from 'meteor/easy:search'
23
import { SingleIndexComponent } from 'meteor/easysearch:components'
34

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

17-
methods.search(str)
18+
super.search(str)
1819

19-
return methods.getCursor()
20+
return this.index.getComponentMethods(this.name).getCursor()
2021
}
2122

2223
/**

packages/easysearch:autosuggest/package.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package.describe({
22
name: 'easysearch:autosuggest',
33
summary: "Selectize Autosuggest Component for EasySearch",
4-
version: "2.2.0",
4+
version: "2.2.1",
55
git: "https://github.com/matteodem/meteor-easy-search.git",
66
documentation: 'README.md'
77
});

packages/easysearch:components/lib/base.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ BaseComponent = class BaseComponent extends BlazeComponent {
7070
return {};
7171
}
7272

73+
/**
74+
* @param {String} searchStr
75+
*
76+
* @returns {Boolean}
77+
*/
78+
shouldShowDocuments(searchStr) {
79+
return !this.getData().noDocumentsOnEmpty || 0 < searchStr.length;
80+
}
81+
7382
/**
7483
* Search the component.
7584
*
@@ -78,7 +87,7 @@ BaseComponent = class BaseComponent extends BlazeComponent {
7887
search(searchString) {
7988
check(searchString, String);
8089

81-
const showDocuments = !this.getData().noDocumentsOnEmpty || 0 < searchString.length;
90+
const showDocuments = this.shouldShowDocuments(searchString);
8291

8392
this.eachIndex(function (index, name) {
8493
index.getComponentDict(name).set('showDocuments', showDocuments);

packages/easysearch:components/package.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package.describe({
22
name: 'easysearch:components',
33
summary: "Blaze Components for EasySearch",
4-
version: "2.2.0",
4+
version: "2.2.1",
55
git: "https://github.com/matteodem/meteor-easy-search.git",
66
documentation: 'README.md'
77
});

0 commit comments

Comments
 (0)