-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactPickadate.react.js
More file actions
76 lines (69 loc) · 2.32 KB
/
Copy pathReactPickadate.react.js
File metadata and controls
76 lines (69 loc) · 2.32 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var React = require('react');
var ReactDOM = require('react-dom');
var jQuery = require('jquery');
/**
* A small es6 class to provide pickadate functionality of materializecss framework combined
* with react.js.
* @author Christian Kramer
*/
export default class ReactPickadate extends React.Component {
constructor(props){
super(props);
this.picker = null;
this.state = {value: this.props.value};
this.classes = this.props.classNames;
}
initPicker(){
var self = this;
var inputElement = jQuery(ReactDOM.findDOMNode(this));
inputElement.pickadate({
format: 'dd.mm.yyyy',
formatSubmit: 'dd.mm.yyyy',
closeOnSelect: true,
hiddenName: false,
min: new Date('01.01.2013'),
max: new Date('01.01.2090'),
selectYears: true,
selectMonths: true,
onOpen: function() {},
onClose: function() {},
onRender: function() {},
onStop: function() {},
onSet: function(event) {
if (event.select){
// date selected
// decide wehter you want to select the date via event or the pickadate hidden field
//self.onChange(jQuery('input[name="' + self.props.id + self.suffix + '"]').val());
self.onChange(new Date(event.select).toLocaleDateString());
self.picker.close();
}
}
});
if (!this.picker){
// set picker reference for opening and closing
this.picker = inputElement.pickadate('picker');
}
}
componentDidMount(){
// init the date picker
this.initPicker();
}
onChange(date){
// propagate the change, if there is one
// since this is a timestamp it's up to you to format it
this.props.onChange(date);
this.setState({value: date})
}
onClick(){
// this is the part where we have to open the picker manually
this.picker.open();
}
render(){
return (<input id={this.props.id}
data-value={new Date()}
onClick={this.onClick.bind(this)}
type="text"
className={this.classes}
value={this.state.value}/>)
}
}