-
Notifications
You must be signed in to change notification settings - Fork 835
Open
Labels
flag: needs discussionIssues which needs discussion before implementation.Issues which needs discussion before implementation.type: featureIssues related to new features.Issues related to new features.
Description
Description
Currently, @ValidateIf
allows ignoring all validators on a property based on a condition, but there's no built-in way to conditionally apply custom validation logic while selectively ignoring other validators.
Developers often need a pattern where:
- If condition A is true → apply custom validation logic AND ignore all other validators
- If condition A is false → skip custom validation AND allow other validators to run
Current workarounds are problematic:
- Using
@ValidateIf
inside custom validators ignores the custom validator itself - Manually manipulating validation metadata leads to complex, error-prone code
- No clean way to achieve "either custom validation OR standard validators, but not both"
Use case example:
class User {
@ValidateIfElse(
(obj) => obj.isAdmin, // condition
(value) => value.length > 10, // custom validation when admin
{ message: 'Admin names must be longer than 10 chars' }
)
@IsNotEmpty() // ignored when isAdmin=true, applied when isAdmin=false
@MinLength(3) // ignored when isAdmin=true, applied when isAdmin=false
name: string;
isAdmin: boolean;
}
Metadata
Metadata
Assignees
Labels
flag: needs discussionIssues which needs discussion before implementation.Issues which needs discussion before implementation.type: featureIssues related to new features.Issues related to new features.