wrapp-archive / validate.js

Declarative validation written in javascript
http://validatejs.org/
178 stars 18 forks source link

this.parse() is undefined #26

Closed dim882 closed 10 years ago

dim882 commented 10 years ago

I'm attempting to use moment.js for date validations, and I have a validation rule that's pretty much the same as the XDate example in the documentation:

    birthdate: {
      date: {
        latest: moment().subtract(18, 'years'),
        message: "^You need to be at least 18 years old"
      }
    },

but I get an "Uncaught TypeError: undefined is not a function validate.js:622". It appears it's attempting to call #parse where this is the validators object, not the datetime object, so it fails. I wonder if it's possible I'm calling validate() wrong and screwing up the context, but I can't find anything in my code that would cause that.

Anyway, I'll submit a pull request soon with a fix that works for me, but let me know if this is incorrect.

ansman commented 10 years ago

Hmm, this should refer to the datetime validator when called since validate.js calls each validator like this:

results.push({
  attribute: attr,
  error: validator.call(validator, value, validatorOptions, attr,
                        attributes)
});

Could you add a console.log(this) before line 622 and see what this refers to?

ansman commented 10 years ago

Ah, I found the issue and released 0.3.1

dim882 commented 10 years ago

Ah, I see. Thanks for getting the fix out so quickly!