input icon indicating copy to clipboard operation
input copied to clipboard

React-Widget DateTimePicker errors

Open waynebrantley opened this issue 7 years ago • 11 comments

I cannot seem to get DateTimePicker from React-Widgets to work correctly.

If you open this codesandbox, you will see there are console errors. https://codesandbox.io/s/react-hook-form-hookforminput-xfrup

The errors appear to be about the component expecting the 'value' to be a javascript Date. Using Redux-Form, we have something like this:

value={!input.value ? null : newDate(input.value)} If I create a 'default' value with const methods = useForm({defaultValues:{DatePicker:new Date()}});

It seems to all work. The React-Widget component does support null. I think the issue is here: https://github.com/react-hook-form/react-hook-form-input/blob/master/src/index.tsx#L57

If it is not a checkbox - it sets it to blank - which will not parse as a date and is likely not ignored like a null is. This indeed does fix my issue. You can comment out the import of the npm react-hook-form-hookforminput in my codesandbox and uncomment the one that imports it from local file - which is a cut and paste of the source with the above small change.

Think this change is an acceptable one?

waynebrantley avatar Nov 24 '19 21:11 waynebrantley

Thanks for your feedback I will take a look at it :)

bluebill1049 avatar Nov 24 '19 21:11 bluebill1049

Going to add support for default value and checked

bluebill1049 avatar Nov 24 '19 22:11 bluebill1049

you want to try out this beta version: [email protected]

bluebill1049 avatar Nov 24 '19 23:11 bluebill1049

now we support defaultValue and defaultChecked

bluebill1049 avatar Nov 24 '19 23:11 bluebill1049

https://codesandbox.io/s/react-hook-form-hookforminput-xfrup

doesnt work. I have to be able to set the defaultValue to NULL.
Your code is using defaultValue || '' and that will not let me use null!

I think you will need to just use null as the default unless a defaultValue is sent in. This could be a backward compatibility issue though..

waynebrantley avatar Nov 25 '19 00:11 waynebrantley

aha thanks @waynebrantley easy fix let's check for only undefined so you can still pass null

bluebill1049 avatar Nov 25 '19 01:11 bluebill1049

Ah..yes...good answer. I can confirm this new beta fixes the issue. Close at your convenience.

waynebrantley avatar Nov 25 '19 01:11 waynebrantley

lovely i will release the patch as well :)

bluebill1049 avatar Nov 25 '19 01:11 bluebill1049

Hey, Thanks, after a long search, found this. It helped me resolve my issue

tkatariya avatar Jan 08 '20 18:01 tkatariya

cool glad it helps @tkatariya

bluebill1049 avatar Jan 08 '20 21:01 bluebill1049