react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

Input is not refreshed when selected prop changed to null or undefined

Open marekadamek opened this issue 9 years ago • 7 comments

Version: 0.60.2

Steps to reproduce:

  1. (important) Paste valid input value using ctrl-c ctrl-v
  2. 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

marekadamek avatar Nov 14 '17 14:11 marekadamek

This occurs for me when pasting input or manually typing input.

keawade avatar Dec 06 '17 21:12 keawade

I'm facing the same issue as keawade. Thanks for the fix.

bikerp avatar Dec 12 '17 13:12 bikerp

Could you post the fix to this please?

kblodget avatar Dec 14 '17 18:12 kblodget

Also facing this issue. Is there a function to manually clear the input in the meantime?

chrisjpatty avatar Jan 06 '18 00:01 chrisjpatty

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 avatar Jan 06 '18 00:01 chrisjpatty

@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.

keawade avatar Jan 19 '18 15:01 keawade

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.

stale[bot] avatar Aug 30 '19 18:08 stale[bot]