Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.parse() is undefined #26

Closed
d-imal opened this issue Sep 22, 2014 · 3 comments
Closed

this.parse() is undefined #26

d-imal opened this issue Sep 22, 2014 · 3 comments

Comments

@d-imal
Copy link

d-imal commented Sep 22, 2014

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
Copy link
Contributor

ansman commented Sep 22, 2014

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 ansman closed this as completed in 7e7c098 Sep 22, 2014
@ansman
Copy link
Contributor

ansman commented Sep 22, 2014

Ah, I found the issue and released 0.3.1

@d-imal
Copy link
Author

d-imal commented Sep 22, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants