From b0f3632d58828c129116fa2dd634f732077009b7 Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Mon, 13 Feb 2023 12:21:44 -0500 Subject: [PATCH] fix: accept empty string if string is non-required Modify a rule to allow a non-required string with a `minLength` >= 1 to be an empty string --- lib/utils/rules.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/rules.js b/lib/utils/rules.js index c79a16d1..59484841 100644 --- a/lib/utils/rules.js +++ b/lib/utils/rules.js @@ -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))