Skip to content

Commit

Permalink
Merge pull request #411 from mvandenburgh/non-required-field-rule
Browse files Browse the repository at this point in the history
fix: always accept empty string if string is non-required
  • Loading branch information
albanm authored May 22, 2023
2 parents 6faead8 + b0f3632 commit c2ff31c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils/rules.js
Original file line number Diff line number Diff line change
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 || (!required && 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 c2ff31c

Please sign in to comment.