validatorjs icon indicating copy to clipboard operation
validatorjs copied to clipboard

Not working from box

Open shusharin opened this issue 1 year ago • 1 comments

What version of this package are you using? ^3.22.1

What operating system, Node.js, and npm version? macOs, v18.10.0, 8.19.2

What happened?

let Validator = require('validatorjs');

Validator(obj, {
    attribute: 'required|string',
    allow: 'required|boolean',
    values: 'required|array',
  })

  
  not working
  
  TypeError: this.setAttributeFormatter is not a function
at Validator (validator.js:18:8)
  
  Try this:

let Validator = require('validatorjs');
Validator.setAttributeFormatter(function(attribute) {
   return attribute.replace(/_/g, ' ');
});
Validator(obj, {
    attribute: 'required|string',
    allow: 'required|boolean',
    values: 'required|array',
  })

not working

  TypeError: this.setAttributeFormatter is not a function
at Validator (validator.js:18:8)

What did you expect to happen? What did i do wrong? May be in Basic Usage skipped some information?

Are you willing to submit a pull request to fix this bug? Not sure

shusharin avatar Aug 08 '24 09:08 shusharin

I had the same problem when I used "Validator(...)" like a function, instead of a constructor like "new Validator(...)"

iancucatalin1993 avatar Jun 04 '25 04:06 iancucatalin1993