diff --git a/components/date_picker/DatePicker.jsx b/components/date_picker/DatePicker.jsx index 2fab6b3d..a80f81d8 100644 --- a/components/date_picker/DatePicker.jsx +++ b/components/date_picker/DatePicker.jsx @@ -9,6 +9,7 @@ class DatePicker extends React.Component { static propTypes = { className: React.PropTypes.string, error: React.PropTypes.string, + inputFormat: React.PropTypes.func, label: React.PropTypes.string, maxDate: React.PropTypes.object, minDate: React.PropTypes.object, @@ -36,7 +37,8 @@ class DatePicker extends React.Component { render () { const { value } = this.props; - const date = value ? `${value.getDate()} ${time.getFullMonth(value)} ${value.getFullYear()}` : null; + const inputFormat = this.props.inputFormat || time.formatDate; + const date = value ? inputFormat(value) : null; return (
diff --git a/components/date_picker/readme.md b/components/date_picker/readme.md index 629a91e9..e9c7aa03 100644 --- a/components/date_picker/readme.md +++ b/components/date_picker/readme.md @@ -23,6 +23,7 @@ class DatePickerTest extends React.Component {
+ `${value.getDate()}/${value.getMonth()}/${value.getFullYear()}`} onChange={this.handleChange.bind(this, 'date3')} value={this.state.date3} />
); } @@ -40,3 +41,4 @@ class DatePickerTest extends React.Component { | `onChange` | `Function` | | Callback called when the picker value is changed.| | `placeholder` | `String` | | The text string to use like a input placeholder.| | `value` | `Date` | | Date object with the currently selected date. | +| `inputFormat` | `Function` | | Function to format the date displayed on the input. | diff --git a/components/utils/time.js b/components/utils/time.js index ecc53c4c..da5f4410 100644 --- a/components/utils/time.js +++ b/components/utils/time.js @@ -1,4 +1,4 @@ -export default { +const time = { getDaysInMonth (d) { const resultDate = this.getFirstDayOfMonth(d); resultDate.setMonth(resultDate.getMonth() + 1); @@ -175,5 +175,11 @@ export default { dateOutOfRange (date, minDate, maxDate) { return ((minDate && !(date >= minDate)) || (maxDate && !(date <= maxDate))); + }, + + formatDate (date) { + return `${date.getDate()} ${time.getFullMonth(date)} ${date.getFullYear()}`; } }; + +export default time; diff --git a/docs/app/components/layout/main/modules/examples/datepicker_example_1.txt b/docs/app/components/layout/main/modules/examples/datepicker_example_1.txt index cf196019..877bd7fb 100644 --- a/docs/app/components/layout/main/modules/examples/datepicker_example_1.txt +++ b/docs/app/components/layout/main/modules/examples/datepicker_example_1.txt @@ -26,6 +26,13 @@ class DatePickerTest extends React.Component { onChange={this.handleChange.bind(this, 'date2')} value={this.state.date2} /> + + `${value.getDate()}/${value.getMonth()}/${value.getFullYear()}`} + onChange={this.handleChange.bind(this, 'date3')} + value={this.state.date3} + /> ); } diff --git a/spec/components/pickers.jsx b/spec/components/pickers.jsx index 02c5dd0c..fbe2d1b4 100644 --- a/spec/components/pickers.jsx +++ b/spec/components/pickers.jsx @@ -41,6 +41,13 @@ class PickersTest extends React.Component { value={this.state.date2} /> + `${value.getDate()}/${value.getMonth()}/${value.getFullYear()}`} + onChange={this.handleChange.bind(this, 'date3')} + value={this.state.date3} + /> +