2

I have a form with multiple input boxes and when the first input box has focus and if I press Enter then route is changing and navigating somewhere. How can I stop it?

udondan
  • 52,841
  • 19
  • 186
  • 168
Rawat Raman
  • 479
  • 1
  • 5
  • 12

1 Answers1

3

The form is submitted hitting enter.
You can try adding an event that listen to the Enter keypressed like this:

<input ... ng-keypress="keyPressed($event)">

Then in your controller you can just prevent the default behavior for Enter key.

$scope.keyPressed = function(event) {
  if (event.which === 13){
    event.preventDefault();
  }
}  

You can find more info in several other questions around SO

Submit form on pressing Enter with AngularJS
How to use a keypress event in AngularJS?

Community
  • 1
  • 1
pasine
  • 11,031
  • 9
  • 47
  • 77