1

After implementing Simple-Jekyll-Search into my website, I was hoping to be able to populate the search field using jQuery and trigger a search. Unfortunately, it seems to only react on button press.

Can a button-press be simulated to trigger a search?

Opal
  • 81,889
  • 28
  • 189
  • 210
matchai
  • 311
  • 4
  • 10
  • you want to get rid of it's current functionality: i.e. searching as you type? – Said Kholov May 18 '15 at 04:55
  • Ideally not. I'd like to be able to trigger it alternatively by populating the input field with text, using jQuery, and causing a search to occur without the user needing to type. – matchai May 18 '15 at 05:05

1 Answers1

1

Try this then:

$('#yourButton').click(function(){
    $('#search-input').keyup();
});

When you click your button, it will trigger the keyup event on your input.

The library you are using is listening to keyup event:

  function registerInput(){
    opt.searchInput.addEventListener('keyup', function(e){
      if( e.target.value.length == 0 ){
        emptyResultsContainer()
        return
      }
      render( searcher.search(store, e.target.value) )
    })
  }

Found the code from Github source.

Another way to change the library. Modify src/index.js file like this:

$('#yourbutton').click(function(){
    render( searcher.search(store, opt.searchInput.value) );
})
Said Kholov
  • 2,436
  • 1
  • 15
  • 22