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(manager): mutate error object on field-level validation. #703

Merged
merged 1 commit into from
Aug 11, 2020

Conversation

Hyperkid123
Copy link
Member

part of #687

Only handles field-level validation

To enable it for form-level validation, we will need to register all validation functions and run them again after the form level validation passes. We need a way to clear form level validation errors, but do not remove field-level validation results at the same time. The only safe way I can think of is re-run all field-level validators, update the state, and possibly trigger the field render.

We will have also trigger the field render after we run form level validation for invalid fields.

@Hyperkid123 Hyperkid123 added the State manager Form state manager packages. Will be used a state management package for the form renderer. label Aug 11, 2020
@Hyperkid123 Hyperkid123 requested a review from rvsia August 11, 2020 11:19
@Hyperkid123 Hyperkid123 mentioned this pull request Aug 11, 2020
9 tasks
@codecov
Copy link

codecov bot commented Aug 11, 2020

Codecov Report

Merging #703 into state-manager will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff               @@
##           state-manager     #703   +/-   ##
==============================================
  Coverage          92.91%   92.92%           
==============================================
  Files                218      218           
  Lines               3488     3491    +3     
  Branches            1113     1115    +2     
==============================================
+ Hits                3241     3244    +3     
  Misses               247      247           
Impacted Files Coverage Δ
...ckages/form-state-manager/src/utils/manager-api.ts 92.13% <100.00%> (+0.18%) ⬆️
...s/form-state-manager/src/utils/use-subscription.ts 98.66% <100.00%> (+0.01%) ⬆️
packages/form-state-manager/src/utils/validate.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 714497a...29c1f1b. Read the comment docs.

@Hyperkid123 Hyperkid123 force-pushed the form-level-validation-state-mutation branch from cebb62f to 29c1f1b Compare August 11, 2020 11:29
@@ -1,9 +1,13 @@
import AnyObject from './any-object';
import { ManagerApi } from './manager-api';

export interface FormLevelError {
[key: string]: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should support more types. I remember I was using <FormattedMessage /> to return translated message in Sources and it worked.

Copy link
Member Author

@Hyperkid123 Hyperkid123 Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking about this as well. I think we might have to re-visit this topic for the whole package because the field level errors are locked to strings as well. And also all validator return values.

@rvsia rvsia merged commit 20d9086 into state-manager Aug 11, 2020
@Hyperkid123 Hyperkid123 deleted the form-level-validation-state-mutation branch August 11, 2020 11:42
@Hyperkid123
Copy link
Member Author

🎉 This PR is included in version 3.1.0 🎉

The release is available on

Demo can be found here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released State manager Form state manager packages. Will be used a state management package for the form renderer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants