react-bootstrap-datetimepicker icon indicating copy to clipboard operation
react-bootstrap-datetimepicker copied to clipboard

Initially setting a null dateTime breaks the datepicker

Open leoasis opened this issue 9 years ago • 8 comments

Setting a null value initially for the datepicker (or an empty string for that matter) breaks the datepicker. If it is passed a null value, the calendar isn't even shown and there is a NaN title. If passed an empty string, the calendar is shown, but the internal state's selectedDate is invalid, and since every new value is cloned from it, all further values are invalid and the onChange always returns an "invalid date" string.

It would be nice to support a null value in the DateTimeField since sometimes in forms the dates are optional.

leoasis avatar Sep 21 '15 10:09 leoasis

+1 I would like this also

Yuripetusko avatar Oct 01 '15 13:10 Yuripetusko

to empty the input field you have to set an empty default text (see #69): defaultText=""

edy avatar Nov 04 '15 16:11 edy

Here's a workaround for this issue:

<DateTimeField
  inputFormat={ humanDateTimeFormat }
  onChange={ this.onDateTimeChange }
  defaultText={ this.state.date ? moment(this.state.date, 'x').format(humanDateTimeFormat) : '' }
  dateTime={ this.state.date || undefined }
/>

jbroadice avatar Nov 13 '15 19:11 jbroadice

I'd like to see this issue getting fixed. Optional input fields are quite common usecase.

:baby_chick:

jozan avatar Dec 02 '15 12:12 jozan

I'd love to see this get addressed too...

bdittmer avatar Dec 02 '15 18:12 bdittmer

+1 here! Me too.

nunogoncalves avatar Dec 07 '15 16:12 nunogoncalves

:+1: +1 here. As @jozan says, this is a very common usecase, especially with dynamically generated forms.

throoze avatar Jan 27 '16 00:01 throoze

:+1: +1 from me - pretty sure it's messing us up in Redux app.

However, suggestion above does not work for me - :-1: I get broken calendar, if i supply defaultText, but dateTime is undefined.

slangeberg avatar Apr 15 '16 16:04 slangeberg