Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always: false doesn't take any effect #2337

Open
tareksalem opened this issue Dec 9, 2023 · 0 comments
Open

always: false doesn't take any effect #2337

tareksalem opened this issue Dec 9, 2023 · 0 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@tareksalem
Copy link

Description

I can see in the documentation there is an option called always: true which is used in combination with groups to force the field to be validated in all cases, however, I think this defeats the purpose of groups, because if I want to set groups so I don't want the validation to be applied on all cases. This is not the point, the point here is: if I define always: false the validation still be applied however I expect it should not be applied!

Minimal code-snippet showcasing the problem

export class UserModel {
  @IsDefined({ always: true })
  name: string;

  @IsEmail()
  email: string;

  @IsNumber({}, { groups: ["numberGroup"] })
  @Min(10, { always: false, groups: ["numberGroup"] })
  @IsString({ always: false, groups: ["ssGroup"] })
  ss: string | number;

  age: number;

  constructor({ name, email }: { name: string; email: string }) {
    this.name = name;
    this.email = email;
    this.age = 20;
    this.ss = 5;
  }
}

This is the validation function

const user = new UserModel({ name: "test", email: "eee@gmail.com" });

validate(user, {
  skipMissingProperties: true,
}).then((errors) => {
  console.log(errors);
});

Expected behavior

I expect when calling the validate function without specifying any group name then it should validate the object by ignoring the validations with groups or I should have an option to specify it called for example ignore: true | false

Actual behavior

It raises a validation error from the validation constraints that are specified with groups however it shouldn't

@tareksalem tareksalem added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

1 participant