Skip to content

Commit

Permalink
fix: accept empty string if string is non-required
Browse files Browse the repository at this point in the history
Modify a rule to allow a non-required string with a `minLength` >= 1 to
be an empty string
  • Loading branch information
mvandenburgh committed Feb 13, 2023
1 parent 6faead8 commit e6b710b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/rules.js
Expand Up @@ -15,7 +15,7 @@ export const getRules = (schema, fullSchema, options, required, isOneOfSelect) =
}
if (fullSchema.type === 'string' && fullSchema.minLength !== undefined) {
const msg = options.messages.minLength.replace('{minLength}', fullSchema.minLength.toLocaleString(options.locale))
rules.push((val) => (val === undefined || val === null || val.length >= fullSchema.minLength) || msg)
rules.push((val) => (val === undefined || val === null || val === '' || val.length >= fullSchema.minLength) || msg)
}
if (fullSchema.type === 'string' && fullSchema.maxLength !== undefined) {
const msg = options.messages.maxLength.replace('{maxLength}', fullSchema.maxLength.toLocaleString(options.locale))
Expand Down

0 comments on commit e6b710b

Please sign in to comment.