-
Notifications
You must be signed in to change notification settings - Fork 869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot reset value #760
Comments
@michalzubkowicz do u able to find some work around ? facing same issue |
@ganz14, Where value is value of datepicker from state. It will completely rerender component on date change. |
Facing the same issue as well. |
@michalzubkowicz what is the 'nameofpicker'? I tried using a ref, a "name" property, nothing seemed to work, even using what you posted 'nameofpicker ...' |
I had the same issue. It happens when value in |
Hi, same here...it's really annoying. It can render empty value on at first render, then in case of empty value, it just realizes that it's not a truthy value and uses last selected value instead. ad
This is not the case... We are having some valid datetime value in the picker and trying to reset it with empty value so the picker is empty. The problem is that react-datetime/src/DateTime.js Line 522 in 7e30d6c
getSelectedDate() react-datetime/src/DateTime.js Line 499 in 7e30d6c
parseDate react-datetime/src/DateTime.js Line 501 in 7e30d6c
getSelectedDate() returns false...and because of false selected value, then getInputValue() fallbacks to this.state.inputValue react-datetime/src/DateTime.js Line 524 in 7e30d6c
And, yes...workaround with |
Btw another possible workaround is to set const [value, setValue] = useState('');
const dateInputElement = useRef(null);
...
const myResetFunction = () => {
dateInputElement.current.state.inputValue = '';
setValue('');
};
...
<Datetime
ref={dateInputElement}
value={value}
/> |
+1 on this |
I didn't like either of the two proposed workarounds, so I came up with a third one: const datetimeWorkaround = (value) => value === '' ? { value: '' } : {};
...
<Datetime
value={value}
inputProps={{
...datetimeWorkaround(value),
}}
/> Setting |
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 arqex#760.
Your a life saver. |
I'm Submitting a ...
Steps to Reproduce
Expected Results
Value should be empty
Actual Results
Nothing happens
The text was updated successfully, but these errors were encountered: