React-Widget DateTimePicker errors
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?
Thanks for your feedback I will take a look at it :)
Going to add support for default value and checked
you want to try out this beta version: [email protected]
now we support defaultValue and defaultChecked
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..
aha thanks @waynebrantley easy fix let's check for only undefined so you can still pass null
Ah..yes...good answer. I can confirm this new beta fixes the issue. Close at your convenience.
lovely i will release the patch as well :)
Hey, Thanks, after a long search, found this. It helped me resolve my issue
cool glad it helps @tkatariya