Input is not refreshed when selected prop changed to null or undefined
Version: 0.60.2
Steps to reproduce:
- (important) Paste valid input value using ctrl-c ctrl-v
- Manipulate selected prop from outside datepicked component and set it to null or undefined
Result: onChange callback is executed with new value (null/undefined) but label shows old value
Note: Field is properly cleared when using build-in clear button or when the value is selected by click or enter
This occurs for me when pasting input or manually typing input.
I'm facing the same issue as keawade. Thanks for the fix.
Could you post the fix to this please?
Also facing this issue. Is there a function to manually clear the input in the meantime?
I answered my own question, and it may help someone else. After looking through the code it looks like you can manually call the clear function that gets called when you click on the clear button.
First, add a reference to the DatePicker component
<DatePicker ref={datePicker => this.datePicker = datePicker} />
Then you can access the function by calling:
someMemberFunction = (e) => {
this.datePicker.onClearClick(e)
}
This should clear the input.
Note: You do have to pass an event object to this function or it will crash while trying to call e.preventDefault(). If you don't have an event object I suppose you could synthesize one by passing an object like so: this.datePicker.onClearClick({preventDefault: () => {}})
Hopefully that helps in the meantime while the maintainers get around to looking at this and related issues.
@chrisjpatty's work around does not resolve the issue for me. If I manually enter a date and then clear it by setting the value of the moment variable to null, the value is cleared but the text stays in the input field.
The workaround just changes the steps taken to set the value to null. Calling the clear function just passes null to the component's update function which calls my update function instead of just calling my update function directly.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.