From f9d9d2c8115da469c234768c220205feb2a58eb1 Mon Sep 17 00:00:00 2001 From: Sepandar Derakhshandeh <69620649+Sepandard@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:36:24 +0330 Subject: [PATCH] fix(docs): update errorState example to cover handle missing state (#30059) resolves #29750 (cherry picked from commit 23c19be3534d5dd64fc8b1106fa9a33e30ae4f64) --- guides/creating-a-custom-form-field-control.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/guides/creating-a-custom-form-field-control.md b/guides/creating-a-custom-form-field-control.md index a4b66adf0ecb..3911d17073ab 100644 --- a/guides/creating-a-custom-form-field-control.md +++ b/guides/creating-a-custom-form-field-control.md @@ -357,14 +357,14 @@ ngDoCheck() { } private updateErrorState() { - const parent = this._parentFormGroup || this.parentForm; + const parentSubmitted = this._parentFormGroup?.submitted || this._parentForm?.submitted; + const touchedOrParentSubmitted = this.touched || parentSubmitted; - const oldState = this.errorState; - const newState = (this.ngControl?.invalid || this.parts.invalid) && (this.touched || parent.submitted); + const newState = (this.ngControl?.invalid || this.parts.invalid) && touchedOrParentSubmitted; - if (oldState !== newState) { + if (this.errorState !== newState) { this.errorState = newState; - this.stateChanges.next(); + this.stateChanges.next(); // Notify listeners of state changes. } } ```