neumino / thinky

JavaScript ORM for RethinkDB
http://justonepixel.com/thinky/
Other
1.12k stars 128 forks source link

custom validator message #614

Closed GenaANTG closed 3 years ago

GenaANTG commented 7 years ago

Hi! I have a next message after validation:

{ ...
    name: 'ValidationError',
    message: 'Value for [email] must be a valid email.' 
}

How i can change a validator message for specific field? e.g. Email. I was not found any solutions for that in documentation. Thanks!

cur3n4 commented 7 years ago

I don't think there is a way to change the validator message for a specific field. However you should be able to specify your own validation function in your schema and throw the error with your preferred message.

    const Model = thinky.createModel('Model',
      {
         email: type.string().email().validator(function() { 
           throw new Errors.ValidationError("Boo") 
         }) 
       },
      {init: false})