Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Fix broken specs, allow invalid date docu
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgoucher committed Aug 5, 2016
1 parent ece9f32 commit feadad7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
5 changes: 5 additions & 0 deletions docs-site/src/example_components.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import hljs from 'highlight.js'
import Default from './examples/default'
import CodeExampleComponent from './code_example_component'

import AllowInvalidDates from './examples/allow_invalid_dates'
import CustomDateFormat from './examples/custom_date_format'
import CustomClassName from './examples/custom_class_name'
import PlaceholderText from './examples/placeholder_text'
Expand Down Expand Up @@ -38,6 +39,10 @@ export default React.createClass({
title: 'Default',
component: <Default />
},
{
title: 'Allow invalid dates',
component: <AllowInvalidDates />
},
{
title: 'Custom date format',
component: <CustomDateFormat />
Expand Down
38 changes: 38 additions & 0 deletions docs-site/src/examples/allow_invalid_dates.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import moment from 'moment'
import DatePicker from 'react-datepicker'

export default React.createClass({
displayName: 'Allow Invalid Dates',

getInitialState () {
return {
startDate: moment()
}
},

handleChange (date) {
this.setState({
startDate: date
})
},

render () {
return <div className="row">
<pre className="column example__code">
<code className="jsx">
{"<DatePicker"}<br />
    <strong>{"allowInvalidDates"}<br /></strong>
    {"selected={this.state.startDate}"}<br />
    {"onChange={this.handleChange} />"}
</code>
</pre>
<div className="column">
<DatePicker
allowInvalidDates
selected={this.state.startDate}
onChange={this.handleChange} />
</div>
</div>
}
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "HackerOne",
"name": "@concur/react-datepicker",
"description": "Fork of react-datepicker (https://github.com/Hacker0x01/react-datepicker)",
"version": "0.29.0",
"version": "0.30.0",
"license": "MIT",
"homepage": "https://github.com/Hacker0x01/react-datepicker",
"main": "dist/react-datepicker.min.js",
Expand Down
20 changes: 13 additions & 7 deletions src/date_input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ var DateInput = React.createClass({
},

updateState (obj) {
if (!this.props.allowInvalidDates) {
return this.setState({value: obj.value})
}

if (typeof obj.value !== 'undefined') {
this.setState({value: obj.value})
}
Expand All @@ -55,6 +59,8 @@ var DateInput = React.createClass({
handleChange (event) {
if (this.props.allowInvalidDates) {
this.updateState({value: event.target.value})
} else if (this.props.onChange) {
this.props.onChange(event)
}

if (!event.isDefaultPrevented()) {
Expand All @@ -77,8 +83,10 @@ var DateInput = React.createClass({
},

safeDateFormat (props, value) {
if (typeof props.date === 'string' || !props.date) {
return value
if (this.props.allowInvalidDates) {
if (typeof props.date === 'string' || !props.date) {
return value
}
}

return props.date && props.date.clone()
Expand All @@ -87,11 +95,9 @@ var DateInput = React.createClass({
},

handleBlur (event) {
if (!this.props.allowInvalidDates) {
this.updateState({
value: this.safeDateFormat(this.props)
})
}
this.updateState({
value: this.safeDateFormat(this.props)
})

if (this.props.onBlur) {
this.props.onBlur(event)
Expand Down
4 changes: 0 additions & 4 deletions src/date_utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import moment from 'moment'

export function isSameDay (moment1, moment2) {
if (!moment2) {
return false
}

if (moment1 && moment2) {
return moment1.isSame(moment2, 'day')
} else {
Expand Down

0 comments on commit feadad7

Please sign in to comment.