Skip to content

Commit a286258

Browse files
authored
Merge pull request #185 from data-driven-forms/date-time-input-formatting
fix(pf3): date-time picker input format.
2 parents dbf13fb + e0e8bc3 commit a286258

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

packages/pf3-component-mapper/src/form-fields/date-time-picker/date-time-picker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export class DateTimePicker extends React.Component {
117117
isDisabled,
118118
disabledDays,
119119
isClearable,
120+
inputFormat,
120121
} = this.props;
121122
const value = this.createDate();
122123
const inputPlaceholder = getPlaceholder(variant, placeholder);
@@ -132,6 +133,7 @@ export class DateTimePicker extends React.Component {
132133
isDisabled={ isDisabled }
133134
isClearable={ isClearable }
134135
clearValue={ this.clearValue }
136+
inputFormat={ inputFormat }
135137
/>
136138
<Overlay
137139
show={ isOpen }
@@ -176,7 +178,7 @@ DateTimePicker.propTypes = {
176178
closeOnDaySelect: PropTypes.bool,
177179
onChange: PropTypes.func.isRequired,
178180
isClearable: PropTypes.bool,
179-
pristine: PropTypes.bool,
181+
inputFormat: PropTypes.string,
180182
};
181183

182184
DateTimePicker.defaultProps = {

packages/pf3-component-mapper/src/form-fields/date-time-picker/picker-input.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { FormControl, Icon, Form } from 'patternfly-react';
44
import MomentLocaleUtils from 'react-day-picker/moment';
55
import './date-picker-styles.scss';
66

7-
const PickerInput = ({ variant, selectedDay, locale, handleOverlayToggle, isDisabled, isClearable, clearValue, ...props }) =>(
7+
const PickerInput = ({ variant, selectedDay, locale, handleOverlayToggle, isDisabled, isClearable, clearValue, inputFormat, ...props }) =>(
88
<Form.InputGroup style={{ cursor: isDisabled ? 'not-allowed' : 'pointer' }} disabled={ isDisabled }>
99
<FormControl
1010
readOnly={ true }
1111
{ ...props }
12-
value={ selectedDay ? MomentLocaleUtils.formatDate(selectedDay, variant === 'date-time' ? 'LLL' : 'L', locale) : '' }
12+
value={ selectedDay ? MomentLocaleUtils.formatDate(selectedDay, inputFormat || variant === 'date-time' ? 'LLL' : 'L', locale) : '' }
1313
type="text"
1414
style={{
1515
cursor: isDisabled ? 'not-allowed' : 'pointer',
@@ -39,6 +39,7 @@ PickerInput.propTypes = {
3939
isDisabled: PropTypes.bool,
4040
isClearable: PropTypes.bool,
4141
clearValue: PropTypes.func.isRequired,
42+
inputFormat: PropTypes.string,
4243
};
4344

4445
export default PickerInput;

packages/react-renderer-demo/src/app/pages/renderer/component-api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ This component is using [react-day-picker](https://react-day-picker.js.org/docs/
127127
|isDisabled|bool|disable component|
128128
|disabledDays|array|Mark specific days or a range of days as disabled. [More info](https://react-day-picker.js.org/examples/disabled). In order to store this prop to JSON we allow using string. Any string accepted by Date constructor is valid value. There is an alias for current date: `today`|
129129
|closeOnDaySelect|bool|Close the calendar popover after selecting date.|
130+
|inputFormat|string|Set date format for the input. [Using same convetion as moment.js](https://devhints.io/moment)|
130131

131132
<ExampleLink to='date-picker' />
132133

0 commit comments

Comments
 (0)