Question

From AngularJS documentation on ngForm:
"if a form has one or more input fields and one or more buttons or input[type=submit] then hitting enter in any of the input fields will trigger the click handler on the first button or input[type=submit] (ngClick) and a submit handler on the enclosing form (ngSubmit)"
Question:
Is there any way to trigger certain button instead "first"?

Was it helpful?

Solution

button element by default has "submit" type (except in IE), so if you have <button></button> inside your form then that's the button that will be triggered on enter.

Explicitly set the type to "button" if you want to skip that button on enter.

// Will not trigger form submit
<button type="button">Click me</button>

// *Will* trigger form submit
<button>Submit</button>
// or
<button type="submit">Submit</button>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top