When you change the value prop to a blank string, Datetime.getSelectedDate() tries to parse the value using the format
string. This fails for blank values, and then getSelectedDate() falls back to the previously entered input value from this.state.inputValue, ignoring the new value prop and making the reset fail.
Closes #760.
Motivation and Context
I want to have a Reset button that clears two Datetime controls used for date range filtering.
Resetting to a blank value used to work and broke once I upgraded to react-datetime 3.0.1.
760 indicates that other people want this fixed too.
Checklist
[x] I have not included any built dist files (us maintainers do that prior to a new release)
[x] I have added tests covering my changes
[x] All new and existing tests pass
[ ] My changes required the documentation to be updated
[ ] I have updated the documentation accordingly
[ ] I have updated the TypeScript 1.8 type definitions accordingly
[ ] I have updated the TypeScript 2.0+ type definitions accordingly
I have tested that the fix works manually, by modifying the playground like this
no matter how I mangle the renderInput() code in src/DateTime.js. I'm probably missing something stupid, like not running npm build prior to npm test.
Uhh. That was it.
Please advise: the README says There's no need to create a new build for each pull request, but if I don't do that, the new test fails. What should I do?
On the theory that it's easier to drop a commit with a git rebase than to redo it from scratch an unknown time later, I've committed the test, the playground update, and the rebuild separately.
Description
When you change the
value
prop to a blank string, Datetime.getSelectedDate() tries to parse the value using the format string. This fails for blank values, and then getSelectedDate() falls back to the previously entered input value from this.state.inputValue, ignoring the newvalue
prop and making the reset fail.Closes #760.
Motivation and Context
760 indicates that other people want this fixed too.
Checklist
I have tested that the fix works manually, by modifying the playground like this
I have attempted to write a unit test, but failed miserably. Here's my attempt:
The test fails with
and I can't get the form control to render anything other than
no matter how I mangle the
renderInput()
code insrc/DateTime.js
. I'm probably missing something stupid, like not runningnpm build
prior tonpm test
.Uhh. That was it.
Please advise: the README says
There's no need to create a new build for each pull request
, but if I don't do that, the new test fails. What should I do?