"Be sure to mark the schema as nullable" message shouldn't be always shown
See original GitHub issueHey, first time opening issue here, so let me just preface that I love this package. It really hits all the sweet spots and scope of features that I need 😍. Thank you for creating it!
As for the issue:
What happens?
It seems that when the input is null
then there is this ValidationError returned:
... must be a `string` type, but the final value was: `null`.
If "null" is intended as an empty value be sure to mark the schema as `.nullable()`
Problem
First line seems proper and something that is expected.
But the second line seems too verbose and something that should be only returned optionally in the development environment. Currently it’s returned always - without any way to easily disable it
I also think it should not be returned as a ValidationError message, but rather logged as a console warning or something similar.
The line in the source: https://github.com/jquense/yup/blob/master/src/locale.js#L18
Context
In certain cases, I’m returning ValidationError messages to the end user of my application. And my end users should only see the reasons of why their input failed. They shouldn’t see messages intended for a developer.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top GitHub Comments
Try adding .nullable() to the chain of validations.
validationSchema={object().shape({ category: string().required(“Category is required.”).nullable() })}
Hope this helps.
@jquense indeed makes sense
This is however problematic when your application is something like an API service where the end users are actually technical folks and they can e.g. submit JSON that can contain different type of values.