This is how I use DayPickerInput.
<DayPickerInput
className="Range"
onDayChange={this.handleDayChange}
format={'dddd, MMM DD YYYY'}
formatDate={formatDate}
inputProps={this.state.inputProps}
dayPickerProps={{
className: 'Range',
month: new Date(),
disabledDays: disabledDays,
weekdaysShort: weekdaysShort,
selectedDays: this.state.selectedDay,
modifiers: {visits, past: this.isPastDay},
renderDay: this.renderDay,
}}
value={this.state.value}
placeholder=""
/>
In another part of the application was fired datePickerInit custom event. This event is listened in my class, where I use DayPickerInput.
constructor(props) {
super(props);
this.state = this.getInitialState();
this.setData = this.setData.bind(this);
document.addEventListener("datePickerInit", this.setData);
}
Here I'm trying to change input value. When I use empty string '', input value does't change. If I use a non-empty string, for exapmle,"test", input value will be successfully changed. Another values like selectedDay or startDate, endDate are successfully changed too. The problem is only with empty value.
There're no errors, or another visible problems. How can I set empty value to the input? Thanks a lot for your help!
setData (e) {
const data = e.detail;
this.setState({
startDate: data.start_date,
endDate: data.end_date,
visits: data.visits,
selectedDay: undefined,
value: '',
});
}
@gpbl Hi, experiencing the same issue, could you please clarify how it is gonna be done?
Hey, I experienced the same issue, creating a redux form field, using the datepicker -> according to the core code, when the value is empty string, onDayChange is called with first argument undefined:
if (value.trim() === '') {
this.setState({ value });
if (onDayChange) {
onDayChange(undefined, {});
}
return;
}
My solution was redefining the onChange handler, catching the undefined prop :slightly_smiling_face:
@NikitaSasin I cannot reproduce your issue using the latest version:
https://codesandbox.io/s/7m6q1y8xmj
Do you still have this problem? If yes, please write back and help us to replicate it by forking that sandbox. Thanks !
@gpbl I am having the same issue.
I get the prop value from the state. When I type an invalid date on DayPickerInput, like "blablabla", I try to reset the field to empty string after onBlur, but the DayPickerInput doesn't change the input value.
Why this issue was closed? I believe so far this has not been fixed. Or it due with number of this issue. I mean #666 )
Most helpful comment
@gpbl I am having the same issue.
I get the prop value from the state. When I type an invalid date on DayPickerInput, like "blablabla", I try to reset the field to empty string after onBlur, but the DayPickerInput doesn't change the input value.