Open
Description
Which @angular/* package(s) are relevant/related to the feature request?
forms
Description
I'd like to be able to show a required asterisk (*
) when the Validators.required
is added to the reactive forms control.
There doesn't seem to be a way to get this information in any rxjs event or signal way.
My only workaround is to subscribe to formControl.events
, but this ends up with extra noise and is not immediately triggered if changing from one invalid reason to another, etc.
Proposed solution
AbstractControl<any, any>.events: Observable<ControlEvent<any>>
should be extended to include a ValidatorsChangeEvent
export declare class ValidatorsChangeEvent extends ControlEvent {
readonly validators: ValidatorFn[];
readonly source: AbstractControl;
constructor(validators: ValidatorFn[], source: AbstractControl);
}
Alternatives considered
The following doesn't work very well:
const sub = formControl.events
.pipe(
takeUntilDestroyed(this.destroyRef),
map((x) => formControl.hasValidator(Validators.required)),
// only trigger when the value changes
distinctUntilChanged(
(a, b) => a === b,
(x) => x,
),
)
.subscribe((isFormControlRequired) => {