Skip to content

Commit

Permalink
Allow custom query on autosuggest based on input
Browse files Browse the repository at this point in the history
  • Loading branch information
fagiani committed Mar 16, 2021
1 parent 6ce1597 commit 74ba4e2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions assets/js/autosuggest.js
Original file line number Diff line number Diff line change
@@ -128,16 +128,23 @@ function selectItem(input, element) {
* Build the search query from the search text - the query is generated in PHP
* and passed into the front end as window.epas = { "query...
*
* @param {object} originating input field
* @returns {string} json string
*/
function getJsonQuery() {
function getJsonQuery(input) {
if (typeof window.epas === 'undefined') {
const error = 'No epas object defined';

// eslint-disable-next-line no-console
console.warn(error);
return { error };
}

// allow for customized query before sending it to
// the search fetch endpoint based on the input
if (typeof window.epCustomQuery !== 'undefined') {
return window.epCustomQuery(window.epas, input);
}

return window.epas;
}
@@ -565,7 +572,7 @@ function init() {
const placeholder = 'ep_autosuggest_placeholder';

// retrieves the PHP-genereated query to pass to ElasticSearch
const queryJSON = getJsonQuery();
const queryJSON = getJsonQuery(input);

if (queryJSON.error) {
return;

0 comments on commit 74ba4e2

Please sign in to comment.