@uncinc/uncinc-react-kitchen-sink 2.11.1 → 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,
@@ -116,11 +119,28 @@ var DateSelect = function DateSelect(props) {
116
119
  useEffect(function () {
117
120
  hideYear && setYear(fixedYear || new Date().getFullYear());
118
121
 
122
+ // In some cases, this element can re-render while there's already a value in the Formik Context.
123
+ // For example, when we build a Webform with multiplate pages, and you go báck a page.
124
+ //
125
+ // The values will still be in the Formik Context, but we need to set them again in useState
126
+ if (value) {
127
+ value.getDate() && setDay(value.getDate());
128
+
129
+ // months are zero-indexed
130
+ value.getMonth() !== undefined && setMonth(value.getMonth() + 1);
131
+ value.getFullYear() && setYear(value.getFullYear());
132
+ }
133
+
119
134
  // All options are filled, start validation
120
135
  if (required && (!day || !month || !year)) {
121
136
  setFieldError(fieldName, requiredError);
122
137
  } else if (day && month && year) {
123
- var date = new Date("".concat(year, "-").concat(month, "-").concat(day));
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)));
124
144
  setFieldValue(fieldName, date);
125
145
  }
126
146
  }, [isSubmitting, day, month, year]);
@@ -131,7 +151,7 @@ var DateSelect = function DateSelect(props) {
131
151
  if (required && (!day || !month || !year)) {
132
152
  return requiredError || t(['webform.components.date_select.required', 'webform.required', 'webform_required']);
133
153
  }
134
- var date = new Date("".concat(year, "-").concat(month, "-").concat(day));
154
+ var date = new Date("".concat(year, "-").concat(toTwoDigits(month), "-").concat(toTwoDigits(day)));
135
155
  if (!(
136
156
  // Take note of the exclamation mark
137
157
  date.getDate() === day && date.getMonth() + 1 === month && date.getFullYear() === year)) {
@@ -20,12 +20,12 @@ var Number = function Number(props) {
20
20
  return requiredError || t(['webform.number.required', 'webform.required', 'webform_required']);
21
21
  }
22
22
  if (min && parseInt(value) < min) {
23
- return t(['webform.number.min', 'webform.min', 'webform_min'], {
23
+ return t(['webform.components.number.min', 'webform.number.min', 'webform.min', 'webform_min'], {
24
24
  min: min
25
25
  });
26
26
  }
27
27
  if (max && parseInt(value) > max) {
28
- return t(['webform.number.max', 'webform.max', 'webform_max'], {
28
+ return t(['webform.components.number.max', 'webform.number.max', 'webform.max', 'webform_max'], {
29
29
  max: max
30
30
  });
31
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uncinc/uncinc-react-kitchen-sink",
3
- "version": "2.11.1",
3
+ "version": "2.11.3",
4
4
  "description": "Default React components that are easily extended.",
5
5
  "author": "uncinc",
6
6
  "license": "MIT",