Skip to content

feat: chain of GenericValidateFunction in useField (#3725) - #3726

Merged
logaretm merged 1 commit into
logaretm:mainfrom
gbaquedano:feat/chain-of-generic-validate-function
Mar 20, 2022
Merged

feat: chain of GenericValidateFunction in useField (#3725)#3726
logaretm merged 1 commit into
logaretm:mainfrom
gbaquedano:feat/chain-of-generic-validate-function

Conversation

@gbaquedano

Copy link
Copy Markdown
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

codecov-commenter commented Mar 13, 2022

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.38%. Comparing base (a56b3a0) to head (e405ae9).
⚠️ Report is 672 commits behind head on main.

Additional details and impacted files
@@            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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Copy link
Copy Markdown
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