First of all, why does the plugin only accept Date objects? I think it would be easier to work with if it accepted date-like strings as well. Check - https://github.com/Hacker0x01/react-datepicker
This comes in handy when there was no date provided. It should default to an empty box with the placeholder and no bugs. Currently its throwing an error -
"Warning: Failed prop type: Invalid prop value of type String supplied to DateInput, expected instance of Date. in DateInput
Let me know if there is something I can do right now to render without any default date and be able to read that as a null or empty string.
Hey @TechyTimo,
I totally agree it that this package should accept strings as well. I'll see what I can do!
Regarding rendering without any default date - it's absolutely supported. If you pass null or don't pass value at all, it should render empty. Or did I not understand your question?
Ok now I understand. So im having to write something like this:
{this.state.date ? (
<DatePicker
name="date" id="date"
value={new Date(this.state.date)}
onChange={this.changeDate}
/>
) : (
<DatePicker
name="date" id="date"
onChange={this.changeDate}
/>
)}
Or:
<DatePicker
name="date" id="date"
value={this.state.date ? new Date(this.state.date) : null }
onChange={this.changeDate}
/>
It would be easier if it was just
<DatePicker
name="date" id="date"
value={this.state.date}
onChange={this.changeDate}
/>
Then the plugin can automatically parse the date if its there or present an empty input with no bugs if the string provided is empty.
Also I think this issue and workaround is essential to include in your documentation.
Ah, now I get how you ended with this issue! I should definitely fix this. Thank you!
Also if you had a date, the erase the date then unfocus the element, it should be able to remain blank.
Hey @TechyTimo, in v6.5.0:
Your last comment may be considered a separate ticket :) I'm tracking it in #29.
Let me know what you think!
Works nicely. Thanks a lot for this
Most helpful comment
Hey @TechyTimo, in v6.5.0:
Your last comment may be considered a separate ticket :) I'm tracking it in #29.
Let me know what you think!