Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add buttons without submit the form in Angular?

In Angular, how I add button without submit the form?

for example I want to call onCancel without submit the form, but update button should be submit the form, and still keep the ngSubmit.

<form [formGroup]="form" (ngSubmit)="submit()">     <p>     <select ...>...</select>     </p>     <p>     <button         type="submit"         mat-raised-button         color="primary">         update     </button>     <button mat-raised-button (click)="onCancel($event)">         cancel     </button>     </p> </form> 
like image 228
Jon Sud Avatar asked Apr 15 '19 08:04

Jon Sud


People also ask

How do you add a button to a form that does not submit?

Set it to type="button" to produce a button that doesn't submit the form. In the words of the HTML Standard: "Does nothing."

Can I put submit button outside form?

You can tie a submit button to a form that the button doesn't live inside of. The trick is to give the form an id and then reference that id with the button's form property. With this setup, clicking the Submit button will cause the form to be submitted.

Is it possible to submit a form without a Submit button yes or no?

As you suggest, We Can Submit a form without the submit button using " Div block in Html web form page ".

Does every form need a submit button?

If you don't have any submit button it is acceptable after all it is an element of form tag and if it is not required you may not add it with in form . This will not broke any web standard.


1 Answers

Just add type='button' to it. A button without any defined type in a form acts like a submit button for the form.

like image 166
Sachin Gupta Avatar answered Sep 17 '22 19:09

Sachin Gupta