Skip to content

Commit daa86c5

Browse files
committed
better handle misformatted date input
1 parent 79e6127 commit daa86c5

File tree

1 file changed

+11
-1
lines changed
  • components/SLDSDatepickerSingleSelect

1 file changed

+11
-1
lines changed

components/SLDSDatepickerSingleSelect/index.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,19 @@ module.exports = React.createClass({
135135
}
136136
},
137137

138+
parseDate(strValue) {
139+
const d = this.props.parser(strValue);
140+
if ( Object.prototype.toString.call(d) === "[object Date]" ) {
141+
if ( !isNaN( d.getTime() ) ) {
142+
return d;
143+
}
144+
}
145+
return new Date();
146+
},
147+
138148
popover() {
139149
if(this.state && this.state.isOpen){
140-
const date = this.state.strValue?this.props.parser(this.state.strValue):this.state.value;
150+
const date = this.state.strValue?this.parseDate(this.state.strValue):this.state.value;
141151
return <SLDSPopover className='slds-dropdown' targetElement={this.refs.date} onClose={this.handleClose}>
142152
<SLDSDatePicker
143153
onChange={this.handleChange}

0 commit comments

Comments
 (0)