Skip to content

Accept observable in mergeValidators/setValidators #56

@rafaelss95

Description

@rafaelss95

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Currently mergeValidators/setValidators doesn't accept observables... we have the validateOn that deals with custom errors, but not with validators.

Expected behavior

I'd expect to see mergeValidators/setValidators accepting observables also, as setValue/patchValue.

What is the motivation / use case for changing the behavior?

I have an use case where I set the validators based on another formControl value, e.g.:

this.formGroup.controls.someControl.setValidators(
  this.formGroup.select(({ dependent }) => dependent).pipe(
    map(dependent => dependent === 'X' ? [Validators.required, Validators.minlength(3)], customValidator),
  ),
);

Also, I think we could add support to accept observable in mergeErrors/setErrors, that would remove the necessity of having validateOn... but that's just an idea.

Environment


Angular version: 10.x.y

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions