simple-react-validator icon indicating copy to clipboard operation
simple-react-validator copied to clipboard

Can't validate MomentJS date object

Open areljannC opened this issue 5 years ago • 7 comments

"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!

areljannC avatar Mar 19 '19 15:03 areljannC

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.

stuyam avatar Mar 20 '19 14:03 stuyam

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

areljannC avatar Mar 20 '19 22:03 areljannC

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!

areljannC avatar Mar 27 '19 04:03 areljannC

@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 avatar Apr 08 '19 14:04 stuyam

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.

stuyam avatar Apr 08 '19 15:04 stuyam

@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."

akiladevv avatar Aug 22 '19 10:08 akiladevv

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

afrojuju1 avatar Apr 03 '20 00:04 afrojuju1