Search code examples
jqueryember.jspreventdefaultenter

Prevent enter key from triggering button


I have a search input box which when a user presses enter needs to do nothing. I am using EmberJS and Jquery with the below code. Currently it works to disable a pop up from being triggered but for some reason in IE9 when enter is pressed a toggle button becomes in focus. Works fine in Chrome. I've tried tabindex and preventDefault but neither do the trick.

   if ($el.hasClass('form-control')) {
                    if ( e.which == 13) {
                        this.get('controller').flipit();

                    }
                }

Thank you.

EDIT------

Here is a snippet of my page. When a user hit enter within the search box the button to the right is getting highlighted. How would I prevent this?

enter image description here


Solution

  • Do this

    $("#inputBox").on('keydown', function(event) {
        if (event.key == "Enter") event.preventDefault();
    });