diff --git a/projects/design-angular-kit/src/lib/abstracts/abstract-form.component.ts b/projects/design-angular-kit/src/lib/abstracts/abstract-form.component.ts index 911b6b6c..fdc170a6 100644 --- a/projects/design-angular-kit/src/lib/abstracts/abstract-form.component.ts +++ b/projects/design-angular-kit/src/lib/abstracts/abstract-form.component.ts @@ -128,11 +128,26 @@ export abstract class AbstractFormComponent extends AbstractComponent i * Fired to check if form control is touched */ ngDoCheck() { - if (this.control.touched) { + if (!this._ngControl?.control) { return; } - if (this._ngControl?.control?.touched) { - this.control.markAsTouched(); + + const ngControl = this._ngControl.control; + if (this.control.touched !== ngControl.touched) { + if (ngControl.touched) { + this.control.markAsTouched(); + } else { + this.control.markAsUntouched(); + } + this._changeDetectorRef.detectChanges(); + } + if (this.control.pristine !== ngControl.pristine) { + if (ngControl.pristine) { + this.control.markAsPristine(); + } else { + this.control.markAsDirty(); + } + this._changeDetectorRef.detectChanges(); } } diff --git a/src/app/form-input/model-driven-validation-example/model-driven-validation-example.component.html b/src/app/form-input/model-driven-validation-example/model-driven-validation-example.component.html index 192d9342..e5ef9f50 100644 --- a/src/app/form-input/model-driven-validation-example/model-driven-validation-example.component.html +++ b/src/app/form-input/model-driven-validation-example/model-driven-validation-example.component.html @@ -38,7 +38,10 @@

Interazione con Form Input dotato di validazione Model Driven

- +
+ + +
Salvato `{{savedValue}}`
diff --git a/src/app/form-input/model-driven-validation-example/model-driven-validation-example.component.ts b/src/app/form-input/model-driven-validation-example/model-driven-validation-example.component.ts index cc951da8..431cc69a 100644 --- a/src/app/form-input/model-driven-validation-example/model-driven-validation-example.component.ts +++ b/src/app/form-input/model-driven-validation-example/model-driven-validation-example.component.ts @@ -36,4 +36,7 @@ export class ModelDrivenValidationExampleComponent { this.savedValue = form.value.myInput; } + markAllAsTouched() { + this.myForm.markAllAsTouched(); + } }