string validator does not return empty string when schema.string.nullableAndOptional() is used #4161
Replies: 4 comments 1 reply
-
anyone please respond @shreeve @allanfreitas @yann-yinn @mul14 |
Beta Was this translation helpful? Give feedback.
-
So basically. You want there to be default values and in current case default value should be empty string? I don't think validator supports default values, but you can add them manually after validation const validated = await request.validate(UserValidator)
// If description isn't set, then give it default value
if (!validated.description) {
validated.description = 'Foo bar and baz'
} |
Beta Was this translation helpful? Give feedback.
-
but this will become cumbersome, is their way to handle this if i have a lot of fields in model. and i might accidentally forgot about some model fields. how to keep it sync with model ? any suggestions . @McSneaky |
Beta Was this translation helpful? Give feedback.
-
If the user description is empty, then it must be represented as Therefore, I recommend marking the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Prerequisites
Node.js and npm version
node: 18.15.0
npm: 9.5.0
Sample Code (to reproduce the issue)
when this validator invoke it does not return the field description if its empty pass from the request.
I want to validator to return empty string so i can update the user description field as empty string
Beta Was this translation helpful? Give feedback.
All reactions