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

fix: example on "always" option in doc #1958

Open
Pernet opened this issue Feb 17, 2023 · 0 comments
Open

fix: example on "always" option in doc #1958

Pernet opened this issue Feb 17, 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

@Pernet
Copy link

Pernet commented Feb 17, 2023

Description

Documentation of "Validation groups" in README should be more explicit for "always" behavior.

import { validate, Min } from 'class-validator';

export class Foo {
  @Min(2, { groups: ['ko' })
  p_ko!: number;
  @Min(2, { groups: ['ok'] })
  p_ok!: number;
  @Min(2)
  p_no_group!: number;
  @Min(2, { always: true, groups: ['ignored'] })
  p_always!: number;
  p_none?: number;
}

let foo = new Foo();
foo.p_ko = 1;
foo.p_ok = 2;

foo.p_no_group = 2;
foo.p_always = 2;
validate(foo, { groups: undefined }); // validation: false on 'p_ko' property
validate(foo, { groups: [] });        // validation: false on 'p_ko' property
validate(foo, { groups: ['ko'] });    // validation: false on 'p_ko' property
validate(foo, { groups: ['ok'] });    // validation: true

foo.p_no_group = 1;
foo.p_always = 1;
validate(foo, { groups: undefined }); // validation: false on 'p_ko' and 'p_no_group' and 'p_always' properties
validate(foo, { groups: [] });        // validation: false on 'p_ko' and 'p_no_group' and 'p_always' properties
validate(foo, { groups: ['ko'] });    // validation: false on 'p_ko' and                  'p_always' properties
validate(foo, { groups: ['ok'] });    // validation: false on                             'p_always' property
@Pernet Pernet added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Feb 17, 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