Skip to content

Commit d04a126

Browse files
authored
docs(form-field): implement error state getter in custom control example (#20275)
The custom input example wasn't showing how to implement the `errorState` getter which means that it can't show error messages. Fixes #20269.
1 parent 6948186 commit d04a126

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div [formGroup]="form">
2-
<mat-form-field appearance="fill">
3-
<mat-label>Phone number</mat-label>
4-
<example-tel-input formControlName="tel" required></example-tel-input>
5-
<mat-icon matSuffix>phone</mat-icon>
6-
<mat-hint>Include area code</mat-hint>
7-
</mat-form-field>
2+
<mat-form-field appearance="fill">
3+
<mat-label>Phone number</mat-label>
4+
<example-tel-input formControlName="tel" required></example-tel-input>
5+
<mat-icon matSuffix>phone</mat-icon>
6+
<mat-hint>Include area code</mat-hint>
7+
</mat-form-field>
88
</div>

src/components-examples/material/form-field/form-field-custom-control/form-field-custom-control-example.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export class MyTelInput
6363
parts: FormGroup;
6464
stateChanges = new Subject<void>();
6565
focused = false;
66-
errorState = false;
6766
controlType = 'example-tel-input';
6867
id = `example-tel-input-${MyTelInput.nextId++}`;
6968
describedBy = '';
@@ -129,6 +128,10 @@ export class MyTelInput
129128
this.stateChanges.next();
130129
}
131130

131+
get errorState(): boolean {
132+
return this.parts.invalid && this.parts.dirty;
133+
}
134+
132135
constructor(
133136
formBuilder: FormBuilder,
134137
private _focusMonitor: FocusMonitor,
@@ -185,7 +188,7 @@ export class MyTelInput
185188
this.describedBy = ids.join(' ');
186189
}
187190

188-
onContainerClick(event: MouseEvent) {
191+
onContainerClick() {
189192
if (this.parts.controls.subscriber.valid) {
190193
this._focusMonitor.focusVia(this.subscriberInput, 'program');
191194
} else if (this.parts.controls.exchange.valid) {

0 commit comments

Comments
 (0)