I am using the Simple-Jekyll-Search library for a website I am currently building.
I want to have a feature where a user can click on a button (imagine tag or category buttons beneath the text input), and that automatically populates the search box with the corresponding tag name, and performs the search.
I have managed to achieve the first part of it by simply setting the search input's value to my desired text, and then I tried to trigger a various key events but unfortunately this doesn't seem to trigger the search. Of course, the search box works normally and results do appear when I type into it manually.
Looking at the library's source file, this seems to be the relevant part to trigger the search, but as far as I can see, I should just need to send a keyup event to the search input to trigger the search.
function registerInput() {
options.searchInput.addEventListener('keyup', function (e) {
if (isWhitelistedKey(e.which)) {
emptyResultsContainer()
search(e.target.value)
}
})
}
However, the following code doesn't work (it fills the text-input with my text, but does no search results come up, no error message):
function tagButtonClick(text) {
document.getElementById('search-input').value = text;
$('#search-input').trigger(jQuery.Event('keyup', {which: 65}));
}
I had a look at this other answer as well, but the approaches there seem to not do anything either.
Any idea how I can achieve the effect I want?