Skip to content
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: pass options.names as a second argument to a Vest suite #584

Merged
merged 1 commit into from Aug 17, 2023

Conversation

vonagam
Copy link
Contributor

@vonagam vonagam commented Jun 25, 2023

React Hook Form has a way to signal to a resolver for which fields validations were requested (options.names/options.fields) and Vest has a way to skip unrequested validations (only/skip/include). But currently that names information gets discarded and Vest cannot utilize that functionality. I think it makes sense to pass names as a second argument.

Note: vestResolver has a second argument which is and never was utilized, other adapters do not have such thing. I think it should be put on note somewhere for removal in next major release.

@jorisre
Copy link
Member

jorisre commented Jun 25, 2023

Thanks for the contribution. Can you add an unit test for this new option?

@vonagam
Copy link
Contributor Author

vonagam commented Jun 25, 2023

Added a test with expected behavior.

@jorisre
Copy link
Member

jorisre commented Jun 25, 2023

Thanks for the test.

The type should be updated as well: https://github.com/react-hook-form/resolvers/blob/master/vest/src/types.ts#L12

@vonagam
Copy link
Contributor Author

vonagam commented Jun 25, 2023

The linked line is one that I made note of. It is unused and can be removed, but this is a breaking change, I assume.

There is no change in types, because all arguments are the same. Currently vest suite signature is undefined. It is simply ReturnType<typeof Vest.create> so can be any function (even though implementation expects that first argument is field values, it is not expressed in types currently).

@vonagam
Copy link
Contributor Author

vonagam commented Jun 27, 2023

Ok, if it is allowed then it makes sense to type the expected call signature of a vest suite. I think this one is reasonable:

(values: TValues, names?: FieldName<TValues>[], context?: TContext) => void

So pass names as the second argument (such signature is shown many times in Vest documentation, mostly for passing to only) and a user supplied validation context as the third argument.

@stale
Copy link

stale bot commented Aug 10, 2023

Thank you for your contributions! This Pull Request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Best, RHF Team ❤️

@stale stale bot added the stale label Aug 10, 2023
@vonagam
Copy link
Contributor Author

vonagam commented Aug 10, 2023

Any thoughts?

@stale stale bot removed the stale label Aug 10, 2023
@jorisre
Copy link
Member

jorisre commented Aug 17, 2023

I tried your code locally, everything seems to work as expected without any breaking changes.
@bluebill1049 Any thoughts? I'm about to merge this PR

@bluebill1049
Copy link
Member

Sounds good to me 👍 @jorisre

@bluebill1049
Copy link
Member

There is a PR here as well: react-hook-form/react-hook-form#10590

@jorisre jorisre merged commit 3519701 into react-hook-form:master Aug 17, 2023
@jorisre
Copy link
Member

jorisre commented Aug 17, 2023

FYI @bluebill1049 I merged but I'll release later with others fixes

@vonagam vonagam deleted the feat-pass-names-to-vest branch August 17, 2023 07:21
@github-actions
Copy link
Contributor

🎉 This PR is included in version 3.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants