New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(forms): export forms utility functions: isFormArray, isFormGroup… #47718
Conversation
616bd72
to
4232ce8
Compare
This commit exports existing utility functions to check for control instances: isFormControl, isFormGroup, isFormRecord, isFormArray Those are useful when implementing validators that use the specifics of one of those control types. To narrow down the type to what it actually is, we can now use the util functions in validators: ``` export const myArrayValidator: ValidatorFn = (control) => { if (!isFormArray(control)) { return null; } // now you can use FormArray-specific members, e.g.: if (control.controls.every(c => !!c.value) { return { myerror: true } } else { return null; } } ```
4232ce8
to
f9eb247
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: fw-forms, public-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed-for: public-api
This PR was merged into the repository by commit a8569e3. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This commit exports existing utility functions to check for control instances: isFormControl, isFormGroup, isFormRecord, isFormArray Those are useful when implementing validators that use the specifics of one of those control types. To narrow down the type to what it actually is, we can now use the util functions in validators:
Before, this had to be done manually:
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information