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

Ability to clear/reset validation #58

Open
Sicria opened this issue Mar 13, 2024 · 4 comments
Open

Ability to clear/reset validation #58

Sicria opened this issue Mar 13, 2024 · 4 comments

Comments

@Sicria
Copy link

Sicria commented Mar 13, 2024

Is it possible to clear the validation state of the form programmatically?

Use-case: I have a form with conditional fields that are controlled via a select, if you choose option1 and submit without a value it creates a validation error on fieldA, if you choose option2 it shows fieldB, the form validation is still success: false due to the previous submission.

Ideally, when switching between fields/schemas I'd like to clear the validation that was done previously.

Calling zo.validate() isn't ideal as that means all of the fields will then be validated, rather than being clean/fresh.


Perhaps a resetValidation or validationReset could be added here?

const validationReset = useCallback(() => {
  setValidation(null);
}, []);

Perhaps it could be zo.validate({ reset: true }) or something similar if the above option isn't ideal?

@esamattis
Copy link
Owner

This seems to be a missing feature for sure.

Perhaps a resetValidation or validationReset could be added here?

Yes. I think I'd prefer resetValidation.

const validationReset = useCallback(() => {
setValidation(null);
}, []);

I think we want to reset submittedOnceRef.current = false too? 🤔

Care to send a PR?

@Sicria
Copy link
Author

Sicria commented Mar 16, 2024

Here's a PR, feel free to make any additional changes you'd require to merge - #59

@RobinStut
Copy link

Hi!
We are running into the same problem.
Are there any status updates on this issue?

@Sicria
Copy link
Author

Sicria commented May 27, 2024

@esamattis is the PR above okay to merge?

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

No branches or pull requests

3 participants