args.value.length not reflecting the true length of the input
st-clair-clarke opened this issue · comments
st-clair-clarke commented
Hi,
I have the following:
export class Onset {
@IsNotEmpty( { message: 'Input required' } )
@MinLength( 6, { message: minLength6Fn } )
mode: string
}
export function minLength6Fn( args: ValidationArguments ) {
switch ( args.value.length ) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
return `Too short, minimum length is ${args.constraints[ 0 ]} characters, but actual is ${args.value.length}`
}
}
Validation is done as shown below:
onset = new Onset()
onset.model = 'Sudden'
transformAndValidate( Onset, currentValue )
.then( ( onset: Onset ) => {
} )
.catch( errors => {
console.log( `onset errors | ${JSON.stringify( errors ) }` )
console.log( errors )
let propError = findPropertyValidationErrors( errors, 'mode' )
console.log( propError )
} )
The validation error printed to console is '["Too short, minimum length is 6 characters, but actual is 5"]
The ${args.value.length} in return Too short, minimum length is ${args.constraints[ 0 ]} characters, but actual is ${args.value.length}
is NOT reflecting the true length of the input.
Is this a bug?
Michał Lytek commented
Yeah, I've encountered the bug with @MinLength
a year ago, I thought it was patched. Anyway - it's related to class-validator so as it's a peer dependency I'm closing the issue.