Material-ui-pickers: Setting default value as empty string for datetimepicker

Created on 29 Jan 2018  路  5Comments  路  Source: mui-org/material-ui-pickers

Environment

| Tech | Version |
|---------------------|---------|
| material-ui-pickers | 1.0.0-beta.13.1 |
| material-ui | 1.0.0-beta.30 |
| React | 16.2.0 |
| Browser | chrome 63.0.3239.132 |
| Platform | windows |

I want to give empty value as default value to datetimepicker. To do this, i tried to set its value to null/undefined/empty string as first value, however it shows invalid date message. How can i set an initial value as empty string? I couldn't see in docs or in examples.

```
the alarmStartTimeKeyword1's value is set to null / undefined or empty string in constructor.

disablePast
placeholder="GG.AA.YYYY SS:DD"
className = {classes.time}
keyboard = {true}
keyboardIcon = { }
invalidDateMessage = {Translator.t('Invalid Date Format')}
animateYearScrolling={true}
ampm={false}
returnMoment={false}
format="DD.MM.YYYY HH:mm"
value = {this.state.alarmStartTimeKeyword1}
onChange = {this.handleDate('alarmStartTimeKeyword1')}
timeIcon = { }
dateRangeIcon = { }
leftArrowIcon = { }
rightArrowIcon = { }
okLabel = {Translator.t('ok')}
cancelLabel = {Translator.t('cancel')}
/>
```

untitled

Expected behavior

Not to give invalid date message for default value if its empty

bug 馃悰

Most helpful comment

Just submitted a fix for that - #199

All 5 comments

Same here, somehow the patch release was a breaking release for us :)
Setting value={''} now automatically triggers the Invalid Date Format error.

~I'll try to submit a pr asap.~ Just realized this would be a functional change which should be discussed.

+1

There is a issue #125.

From a fast look it's a bug.
Maybe introduced in #188

@sakulstra how can i set datetimepicker's value empty for default value? think that i have a page which has some filter parameters and one of the filter parameter comes from that datetimepicker. and because of i cant set its value to empty in initial state, filtering could not work as expected.
so if its not a bug which an empty value could not be set to datetimepicker as an initial state, and it should be something that must be discussed, there must be a best-practice to handle that issue which i faced with during development.

Just submitted a fix for that - #199

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danmce picture danmce  路  3Comments

nicky-dev picture nicky-dev  路  3Comments

dandv picture dandv  路  3Comments

danmce picture danmce  路  3Comments

mnemanja picture mnemanja  路  3Comments