react-bare-forms icon indicating copy to clipboard operation
react-bare-forms copied to clipboard

isValidDate does not check single date values

Open joegasewicz opened this issue 4 years ago • 4 comments

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"});

joegasewicz avatar Jun 10 '21 16:06 joegasewicz

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

rustmn avatar Jun 10 '21 18:06 rustmn

@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

joegasewicz avatar Jun 11 '21 03:06 joegasewicz

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

rustmn avatar Jun 11 '21 07:06 rustmn

@rustmn great , go ahead, thanks

joegasewicz avatar Jun 11 '21 12:06 joegasewicz