Reputation: 481
I am using react-native-datepicker and I need to be able to select any date from the current date which is today.
However, the value for the current date is null. I can select the current date but it has no value. Only the dates after the current date have values.
See below my code.
<DatePicker
date={this.state.date}
mode="date"
placeholder="Select date"
format="YYYY-MM-DD"
minDate={new Date()}
confirmBtnText="Confirm"
cancelBtnText="Cancel"
isClearable
customStyles={{
dateIcon: {
position: 'absolute',
left: 0,
top: 4,
marginLeft: 0
},
dateInput: {
marginLeft: 36,
borderWidth: 0,
right: 0,
color: "grey"
}
}}
onDateChange={(date) => { this.setState({ date: date }); }}
/>
Upvotes: 2
Views: 4493
Reputation: 10808
default state should be a date, not the null or undefined;
this.state ={ date: new Date() }
Upvotes: 1
Reputation: 31565
That happens because you pass minDate={new Date()}
, if you remove it, you will be able to select dates before today.
According to the docs:
minDate
: Restricts the range of possible date values.
So minDate={new Date()}
makes it possible to select only dates that are greater than new Date()
(today).
Upvotes: 1