Reputation: 310
Say I have a form, with a cancel button and a submit button. I want the cancel button to appear to the left of the verify button. When you press "Enter", it should trigger the submit button, not the cancel button. The way Angular2 works, the first button is always the one triggered by an "Enter" key.
<button (click)="onCancel()">Cancel </button>
<button> (click)="onSubmit()">Submit</button>
In this example, the cancel button will be hit instead of the submit. How do I make the submit button fire instead, while still keeping the same order?
Upvotes: 0
Views: 66
Reputation: 214047
According to the w3c specification:
A button element with no type attribute specified represents the same thing as a button element with its type attribute set to "submit".
So I would add type="button"
attribute to cancel button:
<button type="button" (click)="onCancel()">Cancel </button>
^^^^^^^^^^^^^
<button> (click)="onSubmit()">Submit</button>
Upvotes: 2