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: chain of GenericValidateFunction in useField (#3725) #3726

Merged

Conversation

gbaquedano
Copy link
Contributor

πŸ”Ž Overview

This PR adds the feature to use a chain of GenericValidateFunction in rules for useField, and allows it to return multiple errors if bails is set to false.

πŸ€“ Code snippets/examples (if applicable)

const {
  value: value,
  errors: errors,
} = useField(
  'field',
  [
    val => (val ? true : REQUIRED_MESSAGE),
    val => ((val as string)?.length >= 3 ? true : MIN_MESSAGE)
  ],
  { bails: false }
);

If value is not set and and validation is run, errors will be:

[ REQUIRED_MESSAGE, MIN_MESSAGE ]

If bails is true, it will break on the first non passing validation and return a single error. Following this example:

[ REQUIRED_MESSAGE ]

Validations are run following the order they are specified.

βœ” Issues affected

closes #3725

@codecov-commenter
Copy link

Codecov Report

Merging #3726 (e405ae9) into main (a56b3a0) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3726      +/-   ##
==========================================
+ Coverage   96.35%   96.38%   +0.02%     
==========================================
  Files          68       68              
  Lines        1838     1853      +15     
  Branches      457      463       +6     
==========================================
+ Hits         1771     1786      +15     
  Misses         67       67              
Impacted Files Coverage Ξ”
packages/vee-validate/src/useField.ts 98.70% <100.00%> (ΓΈ)
packages/vee-validate/src/validate.ts 97.50% <100.00%> (+0.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update a56b3a0...e405ae9. Read the comment docs.

@logaretm logaretm merged commit 8db4077 into logaretm:main Mar 20, 2022
@logaretm
Copy link
Owner

This is a welcome addition, thank you!

logaretm added a commit that referenced this pull request Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v4] useField(), chain of GenericValidateFunction and bails
3 participants