Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how prevent submit on press enter in twitter bootstrap typeahead plugin

I have a input text and I apply it typeahead plugin for suggesting items, but when I press enter key on input text it submit form.

How can I prevent form submit using twitter bootstrap typeahead plugin?

like image 727
paganotti Avatar asked Nov 25 '12 13:11

paganotti


1 Answers

You can target that specific input by adding an ID to it and simply removing the keydown event for enter like so:

JS

$(document).ready(function() {
  $('form input').keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });
});
like image 148
Andres Ilich Avatar answered Sep 28 '22 09:09

Andres Ilich