react-hook-form / resolvers

📋 Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts and VineJS
https://react-hook-form.com/
MIT License
1.67k stars 151 forks source link

When using `classValidatorResolver`, combining `@IsOptional()` with `@Length()` makes the field required #669

Closed angelxmoreno closed 1 week ago

angelxmoreno commented 3 months ago

Describe the bug When using classValidatorResolver, combining @IsOptional() with @Length() makes the field required

To Reproduce codesandbox.io

Expected behavior I expect @IsOptional() to mark the field as not required, though I feel like i am missing a setting of sorts

jorisre commented 1 week ago

Hi @angelxmoreno, @IsOptional appears to check if the value === null or value === undefined. However, an input returns an empty string. Consider using @IsEmpty