1

I'm using Magento and want to disable the enter key on the search bar. My code is below for search bar:

<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
    <div class="input-box">
        <label for="search"><?php echo $this->__('Search:') ?></label>
        <input id="search" type="search" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" class="input-text required-entry" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" placeholder="<?php echo $this->quoteEscape($this->__('Search entire store here...')) ?>" />
        <button type="submit" title="<?php echo $this->quoteEscape($this->__('Search')) ?>" class="button search-button"><span><span><?php echo $this->__('Search') ?></span></span></button>
    </div>

    <div id="search_autocomplete" class="search-autocomplete"></div>
    <script type="text/javascript">
    //<![CDATA[
        var searchForm = new Varien.searchForm('search_mini_form', 'search', '');
        searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');
    //]]>
    </script>
</form>

Any ideas on how I can do this?

Timothy G.
  • 6,335
  • 7
  • 30
  • 46

2 Answers2

0

Using JQuery in Magento:

$('#search_mini_form').on('keyup keypress', function(event) {
  var key = event.keyCode || event.which;
  if (key === 13) { 
    event.preventDefault();
    return false;
  }
});

put this in your module's layout.xml under defaul tag:

<layout>  
    <default>
        <reference name="head">
            <action method="addJs">
                <script>custom.js</script>
            </action>
        </reference>
    </default>
</layout>
Daniel Lagiň
  • 698
  • 7
  • 18
  • It's not that easy, it depends on magento version and your enviroment settings, but this should help. – Daniel Lagiň Jan 23 '17 at 15:24
  • This might also helps you figure it out - [Disabling the form submit on press of ENTER key](http://www.techawaken.com/disabling-the-form-submit-on-press-of-enter-key/) – Daniel Lagiň Jan 23 '17 at 15:29
0

In react you can disable on form submit

<form id="dashboard-form" onSubmit={(e)=> e.preventDefault()}></form>
Ahsan Azwar
  • 328
  • 1
  • 5
  • 12