lukejagodzinski / meteor-astronomy-validators

https://atmospherejs.com/jagi/astronomy-validators
MIT License
11 stars 13 forks source link

Cannot customize error message for "type" validators #30

Closed chenghanlee closed 9 years ago

chenghanlee commented 9 years ago

Hi Jagi,

We can't seem to set a custom error message for type validators, e.g. Validators.number, Validators.string, and etc., at their constructions.

Currently, it seems like using "validatorError" event is the only way to return custom error message for type validators.

It will be nice if we can customize error messages for type validators during the validator construction like we can for size validators.

Thank you.

lukejagodzinski commented 9 years ago

It works you are probably passing a custom error message as the first argument of a validator and you should pass null as the first and an error message as the second.

// WRONG!
Validators.string('HAS TO BE STRING!');
// CORRECT!
Validators.string(null, 'HAS TO BE STRING!');
chenghanlee commented 9 years ago

Ah. I must have missed this in the documentation. Thank you for the explanation.

lukejagodzinski commented 9 years ago

No problem :-)