@uncinc/uncinc-react-kitchen-sink 2.11.2 → 2.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -11,6 +11,9 @@ import GenericFormElement from '../GenericFormElement';
|
|
|
11
11
|
import SelectInput from '../Select/Input';
|
|
12
12
|
import { useExtendedFormikContext } from '../FormikWrapper';
|
|
13
13
|
import './style.scss';
|
|
14
|
+
function toTwoDigits(value) {
|
|
15
|
+
return ('0' + value).slice(-2);
|
|
16
|
+
}
|
|
14
17
|
var DateSelect = function DateSelect(props) {
|
|
15
18
|
var title = props.title,
|
|
16
19
|
fieldName = props.fieldName,
|
|
@@ -132,7 +135,12 @@ var DateSelect = function DateSelect(props) {
|
|
|
132
135
|
if (required && (!day || !month || !year)) {
|
|
133
136
|
setFieldError(fieldName, requiredError);
|
|
134
137
|
} else if (day && month && year) {
|
|
135
|
-
|
|
138
|
+
// The JavaScript specification only specifies one date format to be universally supported:
|
|
139
|
+
// the date time string format. (See: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date-time-string-format)
|
|
140
|
+
//
|
|
141
|
+
// This means we have to format month and day to a two digits format (we receive them as
|
|
142
|
+
// a single digit), otherwise this will break on some browsers (like Safari).
|
|
143
|
+
var date = new Date("".concat(year, "-").concat(toTwoDigits(month), "-").concat(toTwoDigits(day)));
|
|
136
144
|
setFieldValue(fieldName, date);
|
|
137
145
|
}
|
|
138
146
|
}, [isSubmitting, day, month, year]);
|
|
@@ -143,7 +151,7 @@ var DateSelect = function DateSelect(props) {
|
|
|
143
151
|
if (required && (!day || !month || !year)) {
|
|
144
152
|
return requiredError || t(['webform.components.date_select.required', 'webform.required', 'webform_required']);
|
|
145
153
|
}
|
|
146
|
-
var date = new Date("".concat(year, "-").concat(month, "-").concat(day));
|
|
154
|
+
var date = new Date("".concat(year, "-").concat(toTwoDigits(month), "-").concat(toTwoDigits(day)));
|
|
147
155
|
if (!(
|
|
148
156
|
// Take note of the exclamation mark
|
|
149
157
|
date.getDate() === day && date.getMonth() + 1 === month && date.getFullYear() === year)) {
|