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

Client side validation with zod: Errors don't get cleared when using 'regex' and 'optional' together #389

Closed
fabian-michael opened this issue Mar 23, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@fabian-michael
Copy link

fabian-michael commented Mar 23, 2024

Description
Once you inserted an invalid value into a field with regex and optional in the schema, the error does not get cleared when you empty the field and thus the form is invalid until you insert a valid value.

If applicable, a MRE

https://stackblitz.com/edit/superforms-2-testing-dmk3cn?file=src%2Froutes%2F%2Bpage.svelte

@fabian-michael fabian-michael added the bug Something isn't working label Mar 23, 2024
@ciscoheat
Copy link
Owner

An empty field is the same as an empty string. Use a stringProxy to set it to undefined when empty: https://stackblitz.com/edit/superforms-2-testing-ns3m6n?file=src%2Froutes%2F%2Bpage.svelte

@fabian-michael
Copy link
Author

Shouldn't that be the default, when using optional?

@ciscoheat
Copy link
Owner

There is no way to make it default if you use bind:value, as it will bind to the input field value, which is an empty string when empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants