-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathDatePicker.js
33 lines (27 loc) · 998 Bytes
/
DatePicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react';
import ReactDOM from 'react-dom';
import { danger } from '../util/colors'
class DatePicker extends React.Component {
render() {
const { field, label } = this.props
return(
<div>
<label forHtml={field.name}>{label}</label>
<input type='text' ref='date' className="u-full-width" {...field} />
{field.touched && field.error && <div style={{color: 'white', backgroundColor: danger}}>{field.error}</div>}
</div>
);
}
componentDidMount() {
$(ReactDOM.findDOMNode(this.refs.date)).datepicker({ dateFormat: 'yy-mm-dd' });
$(ReactDOM.findDOMNode(this.refs.date)).on('change', this.handleChange.bind(this));
}
componentWillUnmount() {
}
handleChange(e) {
e.preventDefault()
let date = ReactDOM.findDOMNode(this.refs.date).value
this.props.field.onChange(date);
}
}
export default DatePicker