0

Using react datetime out-of-the-box. It's rendering perfectly and passing data just fine.

The problem is that while I am able to choose a date, the time input is not working properly.

As you know it's an arrow up/down input for changing hour, minutes or am/pm. PROBLEM is that the values revert to default '12:00 AM' the instant I try to change them.

Some code:

<Datetime type="text" className="form-control" id="meeting-name" placeholder="Meeting Time & Date" name="meetingTimestamp" value={this.state.meetingTimestamp} onChange={this.onPickDateTime} />

onPickDateTime(moment) {
  let time = moment.format("YYYY-MM-DD HH:mm:ss");
  this.setState({
    meetingTimestamp: time,
    })
}

I am also referencing the doc's-recommended styling.

Any clues??

208_man
  • 1,440
  • 3
  • 28
  • 59

1 Answers1

0

Don't use format, it will be invalid.

<Datetime type="text" className="form-control" id="meeting-name" placeholder="Meeting Time & Date" name="meetingTimestamp" value={this.state.meetingTimestamp} onChange={this.onPickDateTime} />

onPickDateTime(moment) {
  this.setState({
    meetingTimestamp: moment,
  })
}
Peter Bartels
  • 1,474
  • 1
  • 12
  • 20
  • Thank you @Peter Bartels, but if I don't the format will be invalid for the db. Any way of changing format as defined above without format? – 208_man Apr 07 '18 at 22:19
  • 1
    Your code here doesn't include the database processing. But I guess you need to call moment.format(...) at the point where you are actually calling the api for adding it to the database. – Peter Bartels Apr 08 '18 at 02:14