joegasewicz / react-bare-forms

A bare minimal React form library for quick & simple forms.
https://joegasewicz.github.io/react-bare-forms/
MIT License
20 stars 4 forks source link

isValidDate does not check single date values #145

Open joegasewicz opened 3 years ago

joegasewicz commented 3 years ago

https://github.com/joegasewicz/react-bare-forms/blob/75966d93d7e374bbd0e52f5163e81370d4a89b0e/src/validators.ts#L215

I expect this function to work like this:

isValidDate({startDate: "2021-06-1"});
isValidDate({endDate: "2021-06-1"});
isValidDate({startDate: "2021-06-1", endDate: "2021-06-1"});
rustmn commented 3 years ago

I can do this.

By the way, this check and other like this will fail in the runtime and will lead to error because typescript check types only on compile / development stage - https://github.com/joegasewicz/react-bare-forms/blob/75966d93d7e374bbd0e52f5163e81370d4a89b0e/src/validators.ts#L205

joegasewicz commented 3 years ago

@rustmn Please go ahead with this is issue #145, I will look into if (!fieldValue) { btw this is a value check / cohesion to a boolean , not a type check (typeof). Thanks

rustmn commented 3 years ago

@joegasewicz ok, I'm about this - https://github.com/joegasewicz/react-bare-forms/blob/75966d93d7e374bbd0e52f5163e81370d4a89b0e/src/validators.ts#L203

You expect fieldValue to be a Date object, you check only if it's value is not null / undefined / false, and then interact with it as it were a Date object - https://github.com/joegasewicz/react-bare-forms/blob/75966d93d7e374bbd0e52f5163e81370d4a89b0e/src/validators.ts#L216

Some users may pass an empty object and it will not work as expected, I'll fix it.

joegasewicz commented 3 years ago

@rustmn great , go ahead, thanks