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 authored Mar 15, 2021
1 parent 6ce1597 commit 3bed2ee
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions assets/js/autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,20 @@ function selectItem(input, element) {
*
* @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(windows.epas, input);
}

return window.epas;
}
Expand Down Expand Up @@ -565,7 +571,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;
Expand Down

0 comments on commit 3bed2ee

Please sign in to comment.