Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FormControl events should include when ValidatorFn is added/removed #59030

Copy link
Copy link
Open
@NateRadebaugh

Description

@NateRadebaugh
Issue body actions

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) => {

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.