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

Can't validate MomentJS date object #66

Open
areljannC opened this issue Mar 19, 2019 · 7 comments
Open

Can't validate MomentJS date object #66

areljannC opened this issue Mar 19, 2019 · 7 comments
Assignees

Comments

@areljannC
Copy link

"Date validators require using momentjs and moment objects."

The validation gives that error whenever I try to validate a YYYY-MM-DD date.

I am using an input type of "date" and convert the date to a MomentJS date object and it still gives this error.

I looked everywhere in the documentation that covers how to use MomentJS as well as the CodePen you provided but it doesn't cover dates.

It would be great if you can point me to the right direction and thanks for the help!

@stuyam stuyam self-assigned this Mar 20, 2019
@stuyam
Copy link
Collaborator

stuyam commented Mar 20, 2019

These is an example on the example page using dates: https://dockwa.github.io/simple-react-validator

Here is how it is being used: https://github.com/dockwa/simple-react-validator/blob/master/docs/example.jsx#L87

Also feel free to share you code and I can take a look at it.

@areljannC
Copy link
Author

Hi @stuyam, thank you so much for pointing that out, and it's exactly what I was looking for.

@areljannC areljannC reopened this Mar 27, 2019
@areljannC
Copy link
Author

areljannC commented Mar 27, 2019

https://github.com/areljannC/simple-react-validator-date-error/blob/master/src/App.js

Hi again! The date validation just does not seem to work on my end.
I'm not sure if it's moment.js causing the issue or I'm validating the dates incorrectly. Please take a look at my repo that has some basic code on it.

Once again, your help is very much appreciated and thank you!

@stuyam
Copy link
Collaborator

stuyam commented Apr 8, 2019

@areljannC sorry for the late reply. I just now realized what the issue is. We pull the moment object off the window here to use it: https://github.com/dockwa/simple-react-validator/blob/master/src/simple-react-validator.js#L207

In your case this does not work because you are importing moment and it is not on window. Im not actually sure how to do this. As you can see here in the built source we use UMD (Universal Module Definition) to setup the dependency on react. That is setup here: https://github.com/dockwa/simple-react-validator/blob/master/gulpfile.js#L23

What I am not sure about is how to set that up to optionally look for moment in stead of looking off the window object like we do now. I'll do some more research on this but would love suggestions if anyone has any ideas or has done something like that before.

@stuyam
Copy link
Collaborator

stuyam commented Apr 8, 2019

I guess one option would be requiring moment to be passed in to simple react validator on initialize, which would be probably the simplest way instead of doing magic with the different types of setups to check how and if moment is installed.

@akiladevv
Copy link

@stuyam - can you please tell me some solution to this problem?
I am facing same error "Date validators require using momentjs https://momentjs.com and moment objects."

@afrojuju1
Copy link

I am also having the same issue even with my date being a moment object. please advise

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

4 participants