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
mrdanimal opened this issue Sep 22, 2014 · 3 comments
Closed

this.parse() is undefined #26

mrdanimal opened this issue Sep 22, 2014 · 3 comments

Comments

@mrdanimal
Copy link

@mrdanimal mrdanimal 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 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 in 7e7c098 Sep 22, 2014
@ansman
Copy link
Contributor

@ansman ansman commented Sep 22, 2014

Ah, I found the issue and released 0.3.1

@mrdanimal
Copy link
Author

@mrdanimal mrdanimal 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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants