Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if FormGroup has been submitted [duplicate]

Tags:

angular

In template-driven form, we can check that with the submitted property from NgForm. But how to achieve that in Model-driven form?

like image 673
kyw Avatar asked Jun 15 '17 09:06

kyw


People also ask

How do you know if a form is dirty?

if you want to see if the form is dirty you should check the viewModel in kendo way sample. basically I've created a viewModel which is impements the ObservableObject interface and has a two way binding with the form's container.

What is dirty in Angular form?

When the user changes the value in the watched field, the control is marked as "dirty" When the user blurs the form control element, the control is marked as "touched"

What is FormGroup FormBuilder FormControl?

FormControl is used to keep track of the value and validation status of an individual form control. We also have the following directives: FormControlName is a directive that links a FormControl in a FormGroup to a form control by name.

What is dirty reactive form?

touched means the user has entered the form. dirty / ! pristine means the user has made a modification.


2 Answers

I just found out you can use ngForm together with formGroup:

<form [formGroup]='form' #ngForm="ngForm" (ngSubmit)='validation(ngForm)' 
  [ngClass]="{ 'form-unsubmitted': !ngForm.submitted}">
like image 77
kyw Avatar answered Oct 11 '22 03:10

kyw


Create one variable IsSubmitted = false into component. Once submit a button you can set it true into onSubmit() function. for example :

onSubmit(): void{
     this.isSubmited = true;
  // code....
}

set it again to false after response

like image 42
Shailesh Ladumor Avatar answered Oct 11 '22 03:10

Shailesh Ladumor