In template-driven form, we can check that with the submitted
property from NgForm
. But how to achieve that in Model-driven form?
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.
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"
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.
touched means the user has entered the form. dirty / ! pristine means the user has made a modification.
I just found out you can use ngForm
together with formGroup
:
<form [formGroup]='form' #ngForm="ngForm" (ngSubmit)='validation(ngForm)'
[ngClass]="{ 'form-unsubmitted': !ngForm.submitted}">
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With