feat(ConnectedForm): Allowing customValidations to be passed to form groups and connected inputs for dynamic validations
#3252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds the ability to pass custom validation objects to specific inputs in addition to the validations already included on the top level of the form. This is important because form-level validations are not easy to change dynamically because of both memoization and the need for accessing values "after" the form is instantiated.
There are a few threads kind of about this on the rhf github, but the general conclusions seem to be "you need to be able to access the
getValuesfunction when you create your validation rules" and "inlining on the register itself is the place to do wonky stuff".Since our connected inputs don't actually do the registering themselves and instead hand that responsibility off to the
useFieldhook, I have modified theuseFieldhook to acceptcustomValidationswhich can be passed to theFormGroupor the input itself. In either case, the custom rules will trickle intouseFieldand successfully MERGE those rules with the ones coming from the form, withcustomValidationstaking priority (since one might want to override a form level rule but the opposite seems unlikely to me).PR Checklist
Testing Instructions
Don't make me tap the sign.
PR Links and Envs