Skip to content

Commit 5bbc6da

Browse files
OpusCapita#58 Restrict enter invalid value for DateInput and DateRangeInput (PR OpusCapita#59)
* Minor change - add translations for clear button ("en", "de" locales)
1 parent 58083d6 commit 5bbc6da

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

src/client/components/DateInput/DateInput.react.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ class DateInput extends Component {
283283
tabIndex="-1"
284284
onClick={this.handleReset}
285285
disabled={disabled}
286+
title={getMessage(locale, 'clearValue')}
286287
>
287288
288289
</InputAddonButton>

src/client/components/DateInputField/DateInputField.react.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let propTypes = {
99
dateFormat: PropTypes.string,
1010
disabled: PropTypes.bool,
1111
locale: PropTypes.string,
12+
error: PropTypes.bool,
1213
onChange: PropTypes.func,
1314
onError: PropTypes.func,
1415
onRef: PropTypes.func,
@@ -20,6 +21,7 @@ let defaultProps = {
2021
dateFormat: 'dd/MM/yyyy',
2122
disabled: false,
2223
locale: 'en',
24+
error: false,
2325
onChange: () => {},
2426
onError: () => {},
2527
onRef: () => {},
@@ -36,7 +38,7 @@ class DateInputField extends Component {
3638
}
3739

3840
componentWillReceiveProps(nextProps) {
39-
if (this.props.value !== nextProps.value || this.props.dateFormat !== nextProps.dateFormat) {
41+
if (this.props.error || this.props.value !== nextProps.value || this.props.dateFormat !== nextProps.dateFormat) {
4042
let inputValue = nextProps.value ? dayjs(nextProps.value.toISOString()).format(nextProps.dateFormat) : '';
4143
this.setState({ inputValue });
4244
}
@@ -49,6 +51,7 @@ class DateInputField extends Component {
4951
validate(dateString, dateFormat) {
5052
const i18nCompatibleFormat = dateFormat.replace(/D/g, 'd').replace(/Y/g, 'y');
5153
const dc = new DateConverter(i18nCompatibleFormat);
54+
5255
try {
5356
const date = dc.stringToValue(dateString);
5457
const value = !dateString.length ? null : date;
@@ -73,6 +76,7 @@ class DateInputField extends Component {
7376
className,
7477
dateFormat,
7578
disabled,
79+
error, // eslint-disable-line no-unused-vars
7680
locale, // eslint-disable-line no-unused-vars
7781
onChange, // eslint-disable-line no-unused-vars
7882
onError, // eslint-disable-line no-unused-vars

src/client/components/DateRangeInput/DateRangeInput.SCOPE.react.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class DateRangeInputScope extends Component {
3939
render() {
4040
return (
4141
<div>
42+
<button onClick={() => this.setState({ value1: [null, null] })}>Reset</button>
4243
{this._renderChildren()}
4344
</div>
4445
);

src/client/components/DateRangeInput/DateRangeInput.react.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ class DateRangeInput extends Component {
433433
tabIndex="-1"
434434
onClick={this.handleReset}
435435
disabled={disabled}
436+
title={getMessage(locale, 'clearValue')}
436437
>
437438
438439
</InputAddonButton>
@@ -471,6 +472,7 @@ class DateRangeInput extends Component {
471472
className="opuscapita_date-range-input__input-field opuscapita_date-range-input__left-input-field"
472473
dateFormat={dayjsCompatibleDateFormat}
473474
disabled={disabled}
475+
error={error}
474476
onBlur={(e) => this.handleBlur(e, 'from')}
475477
onFocus={(e) => this.handleFocus(e, 'from')}
476478
onChange={(date) => this.handleRangeChange([date, value[1]])}
@@ -485,6 +487,7 @@ class DateRangeInput extends Component {
485487
className="opuscapita_date-range-input__input-field opuscapita_date-range-input__right-input-field"
486488
dateFormat={dayjsCompatibleDateFormat}
487489
disabled={disabled}
490+
error={error}
488491
onBlur={(e) => this.handleBlur(e, 'to')}
489492
onFocus={(e) => this.handleFocus(e, 'to')}
490493
onChange={(date) => this.handleRangeChange([value[0], date])}

src/client/components/translations.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const translations = {
1010
previousMonth: 'Previous month',
1111
last30Days: 'Last 30 days',
1212
thisMonth: 'This month',
13-
nextMonth: 'Next month'
13+
nextMonth: 'Next month',
14+
clearValue: 'Clear value'
1415
},
1516
de: {
1617
selectDateRange: 'Datumsbereich auswählen',
@@ -23,7 +24,8 @@ const translations = {
2324
previousMonth: 'Vorheriger Monat',
2425
last30Days: 'Letzte 30 Tagen',
2526
thisMonth: 'Dieser Monat',
26-
nextMonth: 'Nächster Monat'
27+
nextMonth: 'Nächster Monat',
28+
clearValue: 'Inhalt löschen'
2729
},
2830
ru: {
2931
selectDateRange: 'Выберите диапазон дат',
@@ -36,7 +38,8 @@ const translations = {
3638
previousMonth: 'Предыдущий месяц',
3739
last30Days: 'Последние 30 дней',
3840
thisMonth: 'Этот месяц',
39-
nextMonth: 'Следующий месяц'
41+
nextMonth: 'Следующий месяц',
42+
clearValue: ''
4043
},
4144
fi: {
4245
selectDateRange: 'Valitse päivämääräväli',
@@ -49,7 +52,8 @@ const translations = {
4952
previousMonth: 'Edellinen kuukausi',
5053
last30Days: 'Edelliset 30 päivää',
5154
thisMonth: 'Tämä kuukausi',
52-
nextMonth: 'Seuraava kuukausi'
55+
nextMonth: 'Seuraava kuukausi',
56+
clearValue: ''
5357
},
5458
no: {
5559
selectDateRange: 'Velg datoområde',
@@ -62,7 +66,8 @@ const translations = {
6266
previousMonth: 'Foregående måned',
6367
last30Days: 'Siste 30 dager',
6468
thisMonth: 'Denne måneden',
65-
nextMonth: 'Neste måned'
69+
nextMonth: 'Neste måned',
70+
clearValue: ''
6671
},
6772
sv: {
6873
selectDateRange: 'Välj datumintervall',
@@ -75,7 +80,8 @@ const translations = {
7580
previousMonth: 'Föregående månad',
7681
last30Days: 'SSenaste 30 dagarna',
7782
thisMonth: 'Denna månad',
78-
nextMonth: 'Nästa månad'
83+
nextMonth: 'Nästa månad',
84+
clearValue: ''
7985
}
8086
};
8187

0 commit comments

Comments
 (0)