-
-
Notifications
You must be signed in to change notification settings - Fork 181
-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
getDefaults returns undefined for optional with a default of empty string or false #356
Labels
Comments
dboune
changed the title
getDefaults returns undefined for optional with a default of empty string
getDefaults returns undefined for optional with a default of empty string or false
Jan 7, 2024
fabian-hiller
added
bug
Something isn't working
priority
This has priority
workaround
Workaround fixes problem
labels
Jan 8, 2024
Thanks for reporting this bug. I will change the if-statement to |
fabian-hiller
added a commit
that referenced
this issue
Jan 8, 2024
fabian-hiller
added a commit
that referenced
this issue
Jan 17, 2024
v0.26.0 is available |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Problem
getDefaults
returns undefined for anoptional
with a default set to an empty string orfalse
. I believe it should return the value supplied.Note: This same issue applies to
getFallbacks
withfallback
. In all cases,parse
does the right thing.Example:
I believe the reason for the current behavior may be here:
https://github.com/fabian-hiller/valibot/blob/6578c3304062e6c2e5cb14fc0f4d6dbb1e6eaffb/library/src/methods/getDefaults/getDefaults.ts#L34C3-L34C24
Rationale
I'm currently evaluating a move from TypeBox to Valibot for form validation because dealing with the validation of unions in TypeBox is complex, and potentially maintaining two schemas for input and output is undesirable. We use
Value.Create(Schema)
to obtain the initial state of our form from our "single source of truth" about the shape of the form state object. I was attempting to re-create this with Valibot.In React + MUI, we cannot (or should not) set the initial value of our form fields to undefined unless we intend to operate them uncontrolled, which is discouraged.
Workaround
Using a function to supply the default value renders the desired result.
Misc
Valibot looks very nice overall. Thank you!
The text was updated successfully, but these errors were encountered: