Skip to content

Change the getError and hasError signature to have more flexibility #19734

Description

@rafaelss95

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[X ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Currently the methods AbstractControl#getError and AbstractControl#hasError accept a 2nd. parameter that let you specify the path of the control. Ex:

formGroup.hasError('errorCode', ANYPATH);

However, both of these methods have the following signature:

getError(errorCode: string, path?: string[]): any

 hasError(errorCode: string, path?: string[]): boolean

... and behind the scenes these methods just call the AbstractControl#get method, which one accepts a string or an array of number | string.

Doesn't it make sense to change the signatures to the same of get method?

getError(errorCode: string, path?: string | (number | string)[]): any

 hasError(errorCode: string, path?: string | (number | string)[]): boolean

So, we can just call this method as usual in get.

Expected behavior

Instead of formGroup.hasError('required', ['x', 'y', 'z']) we can have formGroup.hasError('required', 'x.y.z') for example (as we can call in get method).

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

More flexibility.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: formsfeatureLabel used to distinguish feature request from other issuesfreq2: mediumopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions