Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Problem with validation and custom messages. #230

robertklep opened this Issue · 3 comments

3 participants


Sparked by this issue on StackOverflow I created the following testcase:

var juggling = require('jugglingdb');
var Schema = juggling.Schema;

var schema = new Schema('memory');
var User = schema.define('User');
var num = /^\s*\d+\s*$/;

User.validatesPresenceOf('id', {message: "can't be blank"});
User.validatesFormatOf('id', {with: num, message:"is not a number"});
User.validatesFormatOf('id', {with: num, message:"is not a number"}); // yes, twice

var user = new User({ id : '' });

user.isValid(function(valid) {
  if (! valid)
    console.log('invalid', user.errors);

This generates three errors:

invalid { id: [ 'can\'t be blank', 'is blank', 'is blank' ] }

The 2 is blank messages are incorrect (it's the default message for validatesPresenceOf), and it looks like there might be a scoping issue somewhere in the validation code. It also happens with only one validatesFormatOf, by the way.


Format validator also performs the following checks: blank, nullCheck. So that you can specify {allowBlank: true} or {allowNull: true}. So, I don't think it's a bug.


Fair enough (didn't realize it did those checks), although it seems at least confusing that the message returned is the default for the blank check, even if you specify a customized message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.