Vulcan/packages/nova-forms/lib/DateTime.jsx
xavcz 1e2d43662d form api, embedly url, fix posts autovalues
- Form API: updateCurrentValue(fieldName, fieldValue) => updateCurrentValues(newValues: {[fieldName]: fieldValue}) to update one or more fields at once;
- changes on EmbedlyURL: use of currentValues instead of autofilledValues, fix the use of 'media' field on new & edit (assigned server-side in async callback)
- fix Posts schema's autoValue logic: moved to callbacks (it worked on new docs but not triggered on edits)
2017-01-23 15:50:55 +01:00

54 lines
1.4 KiB
JavaScript

import React, { PropTypes, Component } from 'react';
import DateTimePicker from 'react-datetime';
// import moment from 'moment';
class DateTime extends Component {
constructor(props) {
super(props);
this.updateDate = this.updateDate.bind(this);
}
// when the datetime picker has mounted, SmartForm will catch the date value (no formsy mixin in this component)
componentDidMount() {
this.updateDate(this.props.value || new Date());
}
updateDate(date) {
this.context.updateCurrentValues({[this.props.name]: date});
}
render() {
return (
<div className="form-group row">
<label className="control-label col-sm-3">{this.props.label}</label>
<div className="col-sm-9">
<DateTimePicker
value={this.props.value || new Date()}
// newDate argument is a Moment object given by react-datetime
onChange={newDate => this.updateDate(newDate._d)}
format={"x"}
inputProps={{name: this.props.name}}
/>
</div>
</div>
);
}
}
DateTime.propTypes = {
control: React.PropTypes.any,
datatype: React.PropTypes.any,
group: React.PropTypes.any,
label: React.PropTypes.string,
name: React.PropTypes.string,
value: React.PropTypes.any,
};
DateTime.contextTypes = {
addToAutofilledValues: React.PropTypes.func,
updateCurrentValues: React.PropTypes.func,
};
export default DateTime;