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

Error "Validation.js Error: This library (validator.js) validates strings only" on number field #70

Closed
fabiobeoni opened this issue Feb 23, 2017 · 2 comments

Comments

@fabiobeoni
Copy link

fabiobeoni commented Feb 23, 2017

Hello,

I'm getting this error on a number field on my class:

Some model class...

@IsIn([
      Difficulties.EASY,
      Difficulties.MEDIUM,
      Difficulties.DIFFICULT
    ])
    public difficulty:number;
export class Difficulties {
  static EASY:number=0;
  static MEDIUM:number=1;
  static DIFFICULT:number=2;
};

According to this post looks like the validator.js library doesn't work anymore with fields that are not STRING: validatorjs/validator.js#505

Thanks, F.

@bismert
Copy link

bismert commented Aug 9, 2017

I am facing similar problem as @fabiobeoni

@NoNameProvided
Copy link
Member

Hi @fabiobeoni!

I am going to close this as I cannot reproduce this issue with the current release.

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

export class Difficulties {
  static EASY: number = 0;
  static MEDIUM: number = 1;
  static DIFFICULT: number = 2;
};

export class TestClass {
  @IsIn([
    Difficulties.EASY,
    Difficulties.MEDIUM,
    Difficulties.DIFFICULT
  ])
  public difficulty: number;
}

const instance = new TestClass()
instance.difficulty = 9

validate(instance).then(console.log);

This will return with the correct error:

difficulty must be one of the following values: 0,1,2

@typestack typestack locked and limited conversation to collaborators Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants