Avoid "Enter" key on "search_input"

Hi everyone,

Is there a way that if I put this code

<div class="blog-search">
 {% module "search_input" path="@hubspot/search_input" %}
</div> 

I have no way to click the “enter” key so that redirect on the result list on another page BUT just be able to click on one of the result from the dropdown list?

many thanks by advance.

Just to be clear, you want to disable the “Enter” key on input so the user doesn’t get redirected to the results page, instead forcing them to click one of the suggestions?

You could do it with JS

var input = document.getElementsByClassName('hs-search-field__input')[0];
input.addEventListener('keydown', function(e) {
 if (e.key == 'Enter') {
 e.preventDefault();
 }
});

Hi @piersg ,

Many thanks for this quick reaction :slightly_smiling_face:

Yes, it’s exactly for that.

As I’m a noob, I will ask you if I must copy/paste this code here?

Many thanks

Many thanks @piersg

That’s works exactly as expected :slightly_smiling_face: