fix datepicker

This commit is contained in:
yiminghe 2015-06-30 19:28:56 +08:00
parent f1e92c1227
commit 9b23e39491

View File

@ -20,41 +20,51 @@ let defaultCalendarValue = new GregorianCalendar(zhCn);
defaultCalendarValue.setTime(Date.now());
export default React.createClass({
getInitialState() {
getInitialState: function () {
var value = new GregorianCalendar(zhCn);
if (this.props.value) {
value.setTime(new Date(this.props.value).valueOf());
} else {
value.setTime(Date.now());
}
return {
value: ''
value: value
};
},
getDefaultProps() {
componentWillReceiveProps(nextProps){
if ('value' in nextProps) {
var value = new GregorianCalendar(zhCn);
value.setTime(new Date(nextProps.value).valueOf());
this.setState({
value: value
});
}
},
getDefaultProps: function () {
return {
format: 'yyyy-MM-dd',
placeholder: '请选择日期'
placeholder: '请选择日期',
onSelect: function () {
}
};
},
componentDidMount() {
let state = {};
if (this.props.value) {
let value = new GregorianCalendar(zhCn);
value.setTime(new Date(this.props.value));
state.value = value;
}
state.disabled = this.props.disabled || function() {};
this.setState(state);
handleChange: function (v) {
this.setState({
value: v
});
this.props.onSelect(new Date(v.getTime()));
},
handleChange() {
this.props.onSelect(new Date(this.state.value.getTime()));
},
render() {
let calendar = (
render: function () {
var calendar = (
<Calendar
disabledDate={this.state.disabled}
locale={CalendarLocale}
orient={['top', 'left']}
defaultValue={defaultCalendarValue}
showTime={this.props.showTime}
prefixCls="ant-calendar"
showOk={this.props.showTime}
showClear={false} />
disabledDate={this.props.disabled}
locale={CalendarLocale}
orient={['top', 'left']}
defaultValue={defaultCalendarValue}
showTime={this.props.showTime}
prefixCls="ant-calendar"
showOk={this.props.showTime}
showClear={false}/>
);
return (
<Datepicker
@ -63,8 +73,8 @@ export default React.createClass({
formatter={new DateTimeFormat(this.props.format)}
value={this.state.value}
prefixCls="ant-calendar-picker"
onChange={this.props.onSelect}>
<input placeholder={this.props.placeholder} className="ant-calendar-picker-input" />
onChange={this.handleChange}>
<input placeholder={this.props.placeholder} className="ant-calendar-picker-input"/>
</Datepicker>
);
}