Skip to content

feat: add skipIf predicate option to decorator options #1455

@aoi-umi

Description

@aoi-umi

Description

like this
#740

export class ContentSave {
  @IsDefined()
  @MinLength(5)
  title: string;

  @Type()
  submit?: boolean;
}

when submit is true, i want to skip IsDefined , but not minLength
for example:
{title: "111111111", submit: true} => valid
{title: undefined, submit: false} => valid
{title: "1", submit: false} => invalid(MinLength)

Proposed solution

add skipIf on the ValidationOptions

export class ContentSave {
  @IsDefined({
    skipIf: (data) => data.submit !== true
  })
  @MinLength(5)
  title: string;

  @Type()
  submit?: boolean;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions