Skip to content

Commit 23c19be

Browse files
authored
fix(docs): update errorState example to cover handle missing state (angular#30059)
resolves angular#29750
1 parent 225d82a commit 23c19be

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

guides/creating-a-custom-form-field-control.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,14 @@ ngDoCheck() {
357357
}
358358

359359
private updateErrorState() {
360-
const parent = this._parentFormGroup || this.parentForm;
360+
const parentSubmitted = this._parentFormGroup?.submitted || this._parentForm?.submitted;
361+
const touchedOrParentSubmitted = this.touched || parentSubmitted;
361362

362-
const oldState = this.errorState;
363-
const newState = (this.ngControl?.invalid || this.parts.invalid) && (this.touched || parent.submitted);
363+
const newState = (this.ngControl?.invalid || this.parts.invalid) && touchedOrParentSubmitted;
364364

365-
if (oldState !== newState) {
365+
if (this.errorState !== newState) {
366366
this.errorState = newState;
367-
this.stateChanges.next();
367+
this.stateChanges.next(); // Notify listeners of state changes.
368368
}
369369
}
370370
```

0 commit comments

Comments
 (0)