diff --git a/scripts/playground.html b/scripts/playground.html
index fa8bf4f9..f9bb1d3e 100644
--- a/scripts/playground.html
+++ b/scripts/playground.html
@@ -43,7 +43,7 @@
diff --git a/src/lib/DocSearch.js b/src/lib/DocSearch.js
index d7529085..dcd7122a 100644
--- a/src/lib/DocSearch.js
+++ b/src/lib/DocSearch.js
@@ -64,7 +64,7 @@ class DocSearch {
this.apiKey = apiKey;
this.appId = appId;
this.indexName = indexName;
- this.input = DocSearch.getInputsFromSelector(inputSelector);
+ this.inputs = DocSearch.getInputsFromSelector(inputSelector);
this.algoliaOptions = { hitsPerPage: 5, ...algoliaOptions };
const autocompleteOptionsDebug =
autocompleteOptions && autocompleteOptions.debug
@@ -83,15 +83,13 @@ class DocSearch {
this.client = algoliasearch(this.appId, this.apiKey);
this.client.addAlgoliaAgent(`docsearch.js ${version}`);
- let uniqInput = null;
- console.log(this.input);
- for (uniqInput in this.input) {
+
+ for (let i = 0; i < this.inputs.length; i++) {
+ let uniqInput = this.inputs[i];
if (uniqInput) {
- uniqInput = this.input[uniqInput];
if (enhancedSearchInput) {
uniqInput = DocSearch.injectSearchBox(uniqInput);
}
-
this.autocomplete = autocomplete(uniqInput, autocompleteOptions, [
{
source: this.getAutocompleteSource(transformData, queryHook),
@@ -131,6 +129,14 @@ class DocSearch {
throw new Error(usage);
}
+ if (typeof args.inputSelector !== 'string') {
+ throw new Error(
+ `inputSelector:${
+ args.inputSelector
+ } must be a string. Each selector must match only one element and separated by ','`
+ );
+ }
+
if (!DocSearch.getInputsFromSelector(args.inputSelector)) {
throw new Error(
`Error: No input element in the page matches ${args.inputSelector}`
@@ -175,10 +181,13 @@ class DocSearch {
static getInputsFromSelector(selector) {
if (!selector.length) {
return null;
- } else if (selector.length === 1) {
- return [$(selector).filter('input')];
} else {
- return selector.map(s => $(s).filter('input'));
+ const selectors = selector.split(',');
+ if (selectors.length === 1) {
+ return [$(selector).filter('input')];
+ } else {
+ return selectors.map(s => $(s).filter('input'));
+ }
}
}