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
  • 57,263
  • 20
  • 190
  • 175
Rawat Raman
  • 479
  • 1
  • 5
  • 13

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,311
  • 10
  • 49
  • 81