React-date-picker: Plugin should accept strings and an empty string when no date is provided

Created on 3 Dec 2017  路  8Comments  路  Source: wojtekmaj/react-date-picker

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

bug

Most helpful comment

Hey @TechyTimo, in v6.5.0:

  • Ability to clear date was added.
  • You can also pass dates as strings.
  • Empty strings and false is now considered an empty value.

Your last comment may be considered a separate ticket :) I'm tracking it in #29.

Let me know what you think!

All 8 comments

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:

  • Ability to clear date was added.
  • You can also pass dates as strings.
  • Empty strings and false is now considered an empty value.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dozoisch picture dozoisch  路  4Comments

RubberChickenParadise picture RubberChickenParadise  路  6Comments

hyxos picture hyxos  路  4Comments

allys00 picture allys00  路  4Comments

BaherZ picture BaherZ  路  8Comments