Closed
Description
Documentation Feedback
In the example implementation of a MatFormFieldControl
FormGroup
is used. However, validation happens in the value getter:
@Input()
get value(): MyTel | null {
const {value: {area, exchange, subscriber}} = this.parts;
if (area.length === 3 && exchange.length === 3 && subscriber.length === 4) {
return new MyTel(area, exchange, subscriber);
}
return null;
}
I think it would be better if a validator was provided. Then in the value getter, simply the validity of the form would have to be checked:
@Input()
get value(): MyTel | null {
if (this.parts.valid) {
const {value: {area, exchange, subscriber}} = this.parts;
return new MyTel(area, exchange, subscriber);
}
return null;
}
I guess Validators.minLength()
and Validators.maxLength()
would do the job.
Affected documentation page: https://material.angular.io/guide/creating-a-custom-form-field-control