Guide Search On Enter Key Disable Function



2023년 4월 11일에 게시됨

 

Is there is solution to disable the search on enter key press function within Zendesk Guide?

Tried the below codes in our theme scripts but nothing seems to work:

1.
 
  // Submit search on input enter
  $quickSearch.on('keypress', (e) => {
    if (e.which === 13) {
      search();
    }
  });
});
 
 
2.
 
const searchBox = document.querySelector("query"); searchBox.addEventListener("keydown", (event) => { if (event.keyCode === 13) {   event.preventDefault(); }});*/
 
 
3.
 
  $( document ).ready(function() {
  $(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });

0

2

댓글 2개

For anyone that needs the code, this worked for us:

 $(document).ready(function() {
  document.addEventListener('keydown', (e)=>{
    if (e.which == 13 && e.target.id == "query") {
      e.preventDefault()
      e.stopImmediatePropagation()
      //do something
    }
  }, true)
})

0


Hi Ash, sorry for the delay in response. I was looking at this last week and it seems that there is something with the way that we render the search button within our templating language that somehow overrides `preventDefault` or any other variants where we try to interrupt the action from taking place. 

I haven't done any testing with this yet, but you could try to hide the enter button by default and then show it when there is text in that input field. 

0


댓글을 남기려면 로그인하세요.

원하는 정보를 못 찾으셨나요?

새 게시물