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: custom values and errors #3305

Merged
merged 10 commits into from
May 14, 2021
Merged

feat: custom values and errors #3305

merged 10 commits into from
May 14, 2021

Conversation

logaretm
Copy link
Owner

@logaretm logaretm commented May 13, 2021

What

by default, the validation schema ignores errors for non-existent fields, this can be often mistaken for bugs and may not be very intuitive for new users.

This was by design initially to support a use-case of "multi-step" forms, where a schema may partially exist.

However, I have thought about this more and I think this behavior should be customizable.

How

We can introduce a concept of virtual field, basically, the form API would allow you to create custom errors or values.

These fields will be also created if they exist in the schema but didn't have an associated field rendered. This could be a breaking change for some, but I think going forward the schema should be treated as a strict source of truth for the fields that should be rendered.

The use case that would be broken by this behavior is "multi-step" forms, since before this PR a valid partial is considered a valid submission which is problematic more often than not.

For "multi-step" forms we can let it be handled userland, which means you will have to utilize either computed schemas or craft conditional ones to validate each step as its own schema. The official examples will be updated to handle this.

closes #3062

@codecov-commenter
Copy link

codecov-commenter commented May 13, 2021

Codecov Report

Merging #3305 (43b0df6) into main (c915442) will increase coverage by 0.02%.
The diff coverage is 98.49%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3305      +/-   ##
==========================================
+ Coverage   96.66%   96.69%   +0.02%     
==========================================
  Files          65       65              
  Lines        1531     1574      +43     
  Branches      371      380       +9     
==========================================
+ Hits         1480     1522      +42     
- Misses         50       51       +1     
  Partials        1        1              
Impacted Files Coverage Δ
packages/vee-validate/src/Field.ts 100.00% <ø> (ø)
packages/vee-validate/src/validate.ts 96.96% <96.55%> (-0.22%) ⬇️
packages/vee-validate/src/useForm.ts 98.15% <98.75%> (+0.10%) ⬆️
packages/vee-validate/src/useField.ts 98.29% <100.00%> (+<0.01%) ⬆️
packages/vee-validate/src/useIsFieldDirty.ts 100.00% <100.00%> (ø)
packages/vee-validate/src/useIsFieldTouched.ts 100.00% <100.00%> (ø)
packages/vee-validate/src/useIsFieldValid.ts 100.00% <100.00%> (ø)
packages/vee-validate/src/useValidateField.ts 100.00% <100.00%> (ø)
packages/vee-validate/src/useValidateForm.ts 100.00% <100.00%> (ø)

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 c915442...43b0df6. Read the comment docs.

@logaretm logaretm changed the title feat: virtual fields feat: custom values and errors May 14, 2021
@logaretm logaretm marked this pull request as ready for review May 14, 2021 20:54
@logaretm logaretm merged commit 427802b into main May 14, 2021
@logaretm logaretm deleted the feat/virtual-fields branch May 14, 2021 20:56
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.

Common form errors not associated with any specific field
2 participants