Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add onChange to DatePicker #198

Merged
merged 3 commits into from
Jan 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/js/date-picker/date-picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var DatePicker = React.createClass({
formatDate: React.PropTypes.func,
mode: React.PropTypes.oneOf(['portrait', 'landscape', 'inline']),
onFocus: React.PropTypes.func,
onTouchTap: React.PropTypes.func
onTouchTap: React.PropTypes.func,
onChange: React.PropTypes.func
},

windowListeners: {
Expand Down Expand Up @@ -66,12 +67,12 @@ var DatePicker = React.createClass({
initialDate={this.state.dialogDate}
onAccept={this._handleDialogAccept} />
</div>

);
},

getDate: function() {
return this.state.value;
return this.state.date;
},

setDate: function(d) {
Expand All @@ -83,6 +84,7 @@ var DatePicker = React.createClass({

_handleDialogAccept: function(d) {
this.setDate(d);
if (this.props.onChange) this.props.onChange(null, d);
},

_handleInputFocus: function(e) {
Expand All @@ -91,11 +93,8 @@ var DatePicker = React.createClass({
},

_handleInputTouchTap: function(e) {
var dateString = this.refs.input.getValue();
var inputDate = dateString ? new Date(dateString) : new Date();

this.setState({
dialogDate: inputDate
dialogDate: this.getDate()
});

this.refs.dialogWindow.show();
Expand All @@ -108,4 +107,4 @@ var DatePicker = React.createClass({

});

module.exports = DatePicker;
module.exports = DatePicker;