2016-04-18 10:03:53 +09:00
|
|
|
import React, { PropTypes, Component } from 'react';
|
2016-07-07 12:48:35 +02:00
|
|
|
import DateTimePicker from 'react-datetime';
|
2016-06-07 15:03:00 +09:00
|
|
|
import moment from 'moment';
|
2016-04-18 10:03:53 +09:00
|
|
|
|
|
|
|
class DateTime extends Component {
|
2016-07-07 12:48:35 +02:00
|
|
|
// when the datetime picker mounts, NovaForm will catch the date value (no formsy mixin in this component)
|
|
|
|
componentWillMount() {
|
2016-09-07 14:35:49 +02:00
|
|
|
this.context.addToAutofilledValues({[this.props.name]: this.props.value || new Date()});
|
2016-07-07 12:48:35 +02:00
|
|
|
}
|
|
|
|
|
2016-04-18 10:03:53 +09:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="form-group row">
|
|
|
|
<label className="control-label col-sm-3">{this.props.label}</label>
|
2016-07-06 15:53:14 +02:00
|
|
|
<div className="col-sm-9">
|
2016-07-07 12:48:35 +02:00
|
|
|
<DateTimePicker
|
2016-07-06 15:53:14 +02:00
|
|
|
value={this.props.value || new Date()}
|
2016-07-07 12:48:35 +02:00
|
|
|
// newDate argument is a Moment object given by react-datetime
|
2016-09-07 14:35:49 +02:00
|
|
|
onChange={newDate => { this.context.addToAutofilledValues({[this.props.name]: newDate._d}) }}
|
2016-07-06 15:53:14 +02:00
|
|
|
format={"x"}
|
|
|
|
inputProps={{name: this.props.name}}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-04-18 10:03:53 +09:00
|
|
|
</div>
|
2016-07-06 15:53:14 +02:00
|
|
|
);
|
2016-04-18 10:03:53 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DateTime.propTypes = {
|
2016-07-06 15:53:14 +02:00
|
|
|
control: React.PropTypes.any,
|
|
|
|
datatype: React.PropTypes.any,
|
|
|
|
group: React.PropTypes.any,
|
2016-04-18 10:03:53 +09:00
|
|
|
label: React.PropTypes.string,
|
2016-07-06 15:53:14 +02:00
|
|
|
name: React.PropTypes.string,
|
|
|
|
value: React.PropTypes.any,
|
2016-09-07 14:35:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DateTime.contextTypes = {
|
|
|
|
addToAutofilledValues: React.PropTypes.func,
|
2016-09-27 07:30:58 +02:00
|
|
|
updateCurrentValue: React.PropTypes.func,
|
2016-09-07 14:35:49 +02:00
|
|
|
};
|
2016-04-18 10:03:53 +09:00
|
|
|
|
2016-09-27 07:30:58 +02:00
|
|
|
export default DateTime;
|