Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom query on autosuggest based on input #2136

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions assets/js/autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ 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} input - originating input field
* @returns {string} json string
*/
function getJsonQuery() {
function getJsonQuery(input) {
if (typeof window.epas === 'undefined') {
const error = 'No epas object defined';

Expand All @@ -139,6 +140,12 @@ function getJsonQuery() {
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;
}

Expand Down Expand Up @@ -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;
Expand Down