@ukhomeoffice/formio-gds-template 2.0.2 → 3.0.0-bravo

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.
Files changed (150) hide show
  1. package/.github/workflows/build-and-test.yml +3 -3
  2. package/LICENCE.md +21 -0
  3. package/README.md +8 -0
  4. package/eslint.config.mjs +59 -0
  5. package/lib/components/datamap/GDSDataMap.d.ts +5 -14
  6. package/lib/components/datamap/GDSDataMap.d.ts.map +1 -0
  7. package/lib/components/datamap/GDSDataMap.js +9 -29
  8. package/lib/components/datetime/GDSDatetimeComponent.d.ts +43 -22
  9. package/lib/components/datetime/GDSDatetimeComponent.d.ts.map +1 -0
  10. package/lib/components/datetime/GDSDatetimeComponent.js +167 -178
  11. package/lib/components/index.d.ts +3 -0
  12. package/lib/components/index.d.ts.map +1 -0
  13. package/lib/components/index.js +6 -4
  14. package/lib/components/select/GDSSelect.d.ts +143 -0
  15. package/lib/components/select/GDSSelect.d.ts.map +1 -0
  16. package/lib/components/select/GDSSelect.js +340 -0
  17. package/lib/components/selectboxes/GDSCheckBoxes.d.ts +5 -2
  18. package/lib/components/selectboxes/GDSCheckBoxes.d.ts.map +1 -0
  19. package/lib/components/selectboxes/GDSCheckBoxes.js +7 -33
  20. package/lib/components/time/GDSTimeComponent.d.ts +13 -10
  21. package/lib/components/time/GDSTimeComponent.d.ts.map +1 -0
  22. package/lib/components/time/GDSTimeComponent.js +59 -84
  23. package/lib/components/util/TimeHelper.d.ts +6 -4
  24. package/lib/components/util/TimeHelper.d.ts.map +1 -0
  25. package/lib/components/util/TimeHelper.js +13 -16
  26. package/lib/index.d.ts +4 -2
  27. package/lib/index.d.ts.map +1 -0
  28. package/lib/index.js +2 -2
  29. package/lib/templates/gds/button/index.d.ts +1 -0
  30. package/lib/templates/gds/button/index.d.ts.map +1 -0
  31. package/lib/templates/gds/button/index.js +1 -1
  32. package/lib/templates/gds/checkbox/index.d.ts +1 -0
  33. package/lib/templates/gds/checkbox/index.d.ts.map +1 -0
  34. package/lib/templates/gds/checkbox/index.js +1 -1
  35. package/lib/templates/gds/columns/index.d.ts +1 -0
  36. package/lib/templates/gds/columns/index.d.ts.map +1 -0
  37. package/lib/templates/gds/columns/index.js +1 -1
  38. package/lib/templates/gds/component/index.d.ts +1 -0
  39. package/lib/templates/gds/component/index.d.ts.map +1 -0
  40. package/lib/templates/gds/component/index.js +1 -1
  41. package/lib/templates/gds/container/index.d.ts +1 -0
  42. package/lib/templates/gds/container/index.d.ts.map +1 -0
  43. package/lib/templates/gds/container/index.js +1 -1
  44. package/lib/templates/gds/cssClasses.d.ts +1 -0
  45. package/lib/templates/gds/cssClasses.d.ts.map +1 -0
  46. package/lib/templates/gds/datagrid/form.ejs.js +2 -2
  47. package/lib/templates/gds/datagrid/index.d.ts +1 -0
  48. package/lib/templates/gds/datagrid/index.d.ts.map +1 -0
  49. package/lib/templates/gds/datagrid/index.js +1 -1
  50. package/lib/templates/gds/datamap/index.d.ts +1 -0
  51. package/lib/templates/gds/datamap/index.d.ts.map +1 -0
  52. package/lib/templates/gds/datamap/index.js +1 -1
  53. package/lib/templates/gds/datetime/index.d.ts +1 -0
  54. package/lib/templates/gds/datetime/index.d.ts.map +1 -0
  55. package/lib/templates/gds/datetime/index.js +1 -1
  56. package/lib/templates/gds/day/index.d.ts +1 -0
  57. package/lib/templates/gds/day/index.d.ts.map +1 -0
  58. package/lib/templates/gds/day/index.js +1 -1
  59. package/lib/templates/gds/editgrid/index.d.ts +1 -0
  60. package/lib/templates/gds/editgrid/index.d.ts.map +1 -0
  61. package/lib/templates/gds/editgrid/index.js +1 -1
  62. package/lib/templates/gds/field/index.d.ts +1 -0
  63. package/lib/templates/gds/field/index.d.ts.map +1 -0
  64. package/lib/templates/gds/field/index.js +1 -1
  65. package/lib/templates/gds/fieldset/index.d.ts +1 -0
  66. package/lib/templates/gds/fieldset/index.d.ts.map +1 -0
  67. package/lib/templates/gds/fieldset/index.js +1 -1
  68. package/lib/templates/gds/file/index.d.ts +1 -0
  69. package/lib/templates/gds/file/index.d.ts.map +1 -0
  70. package/lib/templates/gds/file/index.js +1 -1
  71. package/lib/templates/gds/iconClass.d.ts +2 -1
  72. package/lib/templates/gds/iconClass.d.ts.map +1 -0
  73. package/lib/templates/gds/iconClass.js +3 -3
  74. package/lib/templates/gds/index.d.ts +3 -2
  75. package/lib/templates/gds/index.d.ts.map +1 -0
  76. package/lib/templates/gds/index.js +72 -64
  77. package/lib/templates/gds/input/index.d.ts +1 -0
  78. package/lib/templates/gds/input/index.d.ts.map +1 -0
  79. package/lib/templates/gds/input/index.js +1 -1
  80. package/lib/templates/gds/label/index.d.ts +1 -0
  81. package/lib/templates/gds/label/index.d.ts.map +1 -0
  82. package/lib/templates/gds/label/index.js +1 -1
  83. package/lib/templates/gds/message/index.d.ts +1 -0
  84. package/lib/templates/gds/message/index.d.ts.map +1 -0
  85. package/lib/templates/gds/message/index.js +1 -1
  86. package/lib/templates/gds/panel/index.d.ts +1 -0
  87. package/lib/templates/gds/panel/index.d.ts.map +1 -0
  88. package/lib/templates/gds/panel/index.js +1 -1
  89. package/lib/templates/gds/radio/index.d.ts +1 -0
  90. package/lib/templates/gds/radio/index.d.ts.map +1 -0
  91. package/lib/templates/gds/radio/index.js +1 -1
  92. package/lib/templates/gds/select/index.d.ts +1 -0
  93. package/lib/templates/gds/select/index.d.ts.map +1 -0
  94. package/lib/templates/gds/select/index.js +1 -1
  95. package/lib/templates/gds/selectOption/index.d.ts +1 -0
  96. package/lib/templates/gds/selectOption/index.d.ts.map +1 -0
  97. package/lib/templates/gds/selectOption/index.js +1 -1
  98. package/lib/templates/gds/selectboxes/index.d.ts +1 -0
  99. package/lib/templates/gds/selectboxes/index.d.ts.map +1 -0
  100. package/lib/templates/gds/selectboxes/index.js +1 -1
  101. package/lib/templates/gds/survey/index.d.ts +1 -0
  102. package/lib/templates/gds/survey/index.d.ts.map +1 -0
  103. package/lib/templates/gds/survey/index.js +1 -1
  104. package/lib/templates/gds/tab/index.d.ts +1 -0
  105. package/lib/templates/gds/tab/index.d.ts.map +1 -0
  106. package/lib/templates/gds/tab/index.js +1 -1
  107. package/lib/templates/gds/table/index.d.ts +1 -0
  108. package/lib/templates/gds/table/index.d.ts.map +1 -0
  109. package/lib/templates/gds/table/index.js +1 -1
  110. package/lib/templates/gds/template.css +27 -0
  111. package/lib/templates/gds/template.css.map +1 -1
  112. package/lib/templates/gds/time/index.d.ts +1 -0
  113. package/lib/templates/gds/time/index.d.ts.map +1 -0
  114. package/lib/templates/gds/time/index.js +1 -1
  115. package/lib/templates/gds/warning/index.d.ts +1 -0
  116. package/lib/templates/gds/warning/index.d.ts.map +1 -0
  117. package/lib/templates/gds/warning/index.js +1 -1
  118. package/lib/templates/gds/wizard/index.d.ts +1 -0
  119. package/lib/templates/gds/wizard/index.d.ts.map +1 -0
  120. package/lib/templates/gds/wizard/index.js +1 -1
  121. package/lib/templates/gds/wizardHeader/index.d.ts +1 -0
  122. package/lib/templates/gds/wizardHeader/index.d.ts.map +1 -0
  123. package/lib/templates/gds/wizardHeader/index.js +1 -1
  124. package/lib/templates/gds/wizardNav/index.d.ts +1 -0
  125. package/lib/templates/gds/wizardNav/index.d.ts.map +1 -0
  126. package/lib/templates/gds/wizardNav/index.js +1 -1
  127. package/lib/templates/index.d.ts +3 -2
  128. package/lib/templates/index.d.ts.map +1 -0
  129. package/lib/templates/index.js +1 -1
  130. package/lib/types.d.ts +37 -0
  131. package/lib/types.d.ts.map +1 -0
  132. package/lib/types.js +2 -0
  133. package/package.json +14 -7
  134. package/src/components/datamap/GDSDataMap.ts +5 -14
  135. package/src/components/datetime/GDSDatetimeComponent.ts +128 -91
  136. package/src/components/index.ts +2 -0
  137. package/src/components/select/GDSSelect.spec.ts +538 -0
  138. package/src/components/select/GDSSelect.ts +418 -0
  139. package/src/components/selectboxes/GDSCheckBoxes.ts +7 -8
  140. package/src/components/time/GDSTimeComponent.ts +37 -27
  141. package/src/components/util/TimeHelper.ts +6 -5
  142. package/src/css.d.ts +4 -0
  143. package/src/templates/gds/datagrid/form.ejs +1 -2
  144. package/src/templates/gds/iconClass.ts +1 -1
  145. package/src/templates/gds/index.ts +43 -33
  146. package/src/templates/gds/template.scss +48 -1
  147. package/src/types.ts +56 -0
  148. package/tsconfig.json +21 -5
  149. package/webpack.config.js +1 -1
  150. package/tslint.json +0 -22
@@ -1,34 +1,54 @@
1
- import {Components} from 'formiojs';
2
- import FormioUtils from 'formiojs/utils';
1
+ import { Components } from '@formio/js';
2
+ import { Utils as FormioUtils } from '@formio/js';
3
3
  import * as _ from 'lodash';
4
4
  import moment from 'moment';
5
5
  import TimeHelper from '../util/TimeHelper';
6
+ import { GDSDatetimeComponentSchema } from '../../types';
6
7
 
7
8
  const Field = Components.components.field;
8
9
  const Day = Components.components.day;
9
10
 
10
- // @ts-ignore
11
11
  export default class GDSDatetimeComponent extends Day {
12
12
 
13
- get format() {
13
+ // Narrow the inherited `component: any` to the GDS datetime schema type.
14
+ // @formio/core provides the DayComponent + DateTimeComponent shapes;
15
+ // GDSDatetimeComponentSchema extends them with hour/minute fields.
16
+ declare component: GDSDatetimeComponentSchema;
17
+
18
+ // Narrow inherited base-class properties from `any` / `{}` to precise types.
19
+ // `declare` emits no runtime code — it only refines the type in this subclass.
20
+ declare refs: {
21
+ hour: HTMLInputElement;
22
+ minute: HTMLInputElement;
23
+ day: HTMLInputElement;
24
+ month: HTMLInputElement;
25
+ year: HTMLInputElement;
26
+ input: HTMLInputElement[];
27
+ };
28
+ declare dataValue: string;
29
+ declare data: Record<string, unknown>;
30
+ declare validators: string[];
31
+ declare shouldDisabled: boolean;
32
+ declare triggerChange: () => void;
33
+
34
+ get format(): string {
14
35
  return 'DD-MM-YYYY';
15
36
  }
16
- // @ts-ignore
17
- get defaultValue() {
37
+
38
+ get defaultValue(): string {
18
39
  let defaultValue = this.component.defaultValue;
19
40
  if (!defaultValue && this.component.defaultDate) {
20
41
  defaultValue = FormioUtils.getDateSetting(this.component.defaultDate);
21
42
  defaultValue = defaultValue ? moment(defaultValue).format() : '';
22
43
  }
23
- return defaultValue;
44
+ return defaultValue ?? '';
24
45
  }
25
46
 
26
- // @ts-ignore
27
- get emptyValue() {
47
+ get emptyValue(): null {
28
48
  return null;
29
49
  }
30
50
 
31
- get parts() {
51
+ get parts(): { day: string | null; month: string | null; year: string | null; hour: string | null; minute: string | null } {
32
52
  return {
33
53
  day: this.getFieldValue('day'),
34
54
  month: this.getFieldValue('month'),
@@ -38,25 +58,18 @@ export default class GDSDatetimeComponent extends Day {
38
58
  };
39
59
  }
40
60
 
41
- private refs: any;
42
- private component: any;
43
- private updateValue: any;
44
- private renderField: any;
45
- private inputDefinition: any;
46
- private checkComponentValidity: any;
47
- private triggerChange: any;
48
-
49
61
  private timeHelper: TimeHelper = new TimeHelper();
50
62
 
51
- public attach(element: any) {
52
- this.loadRefs(element, {hour: 'single', minute: 'single'});
63
+ // element typed as `any` to match the base Day.attach(element: any) override signature
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
65
+ public attach(element: any): Promise<void> {
66
+ this.loadRefs(element, { hour: 'single', minute: 'single' });
67
+
53
68
  this.addEventListener(this.refs.hour, 'input', () => {
54
69
  this.timeHelper.checkAndValidateHour(this.refs.hour);
55
70
  this.setPristine(false);
56
71
  this.checkComponentValidity(this.data, true);
57
- this.updateValue(null, {
58
- modified: true,
59
- });
72
+ this.updateValue(null, { modified: true });
60
73
  this.triggerChange();
61
74
  });
62
75
 
@@ -64,9 +77,7 @@ export default class GDSDatetimeComponent extends Day {
64
77
  this.timeHelper.checkAndValidateMinutes(this.refs.minute);
65
78
  this.setPristine(false);
66
79
  this.checkComponentValidity(this.data, true);
67
- this.updateValue(null, {
68
- modified: true,
69
- });
80
+ this.updateValue(null, { modified: true });
70
81
  this.triggerChange();
71
82
  });
72
83
 
@@ -94,42 +105,65 @@ export default class GDSDatetimeComponent extends Day {
94
105
  this.timeHelper.validateDateInput(this.refs.month, 2);
95
106
  });
96
107
 
97
-
98
108
  return superAttach;
99
109
  }
100
110
 
101
- public init() {
111
+ /**
112
+ * Override t() to remap translation keys emitted by @formio/core validators that
113
+ * differ from the @formio/js English translation map.
114
+ *
115
+ * @formio/core's date validator emits FieldError('invalidDate', ...) (camelCase).
116
+ * @formio/js translations only define 'invalid_date' (underscore). When t()
117
+ * cannot find 'invalidDate' it returns the raw key as the error message.
118
+ *
119
+ * We map the camelCase core keys to their underscored @formio/js equivalents so
120
+ * the user sees a proper human-readable message.
121
+ */
122
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
123
+ public t(text: any, ...args: any[]): any {
124
+ const keyMap: Record<string, string> = {
125
+ invalidDate: 'invalid_date',
126
+ };
127
+ return super.t(keyMap[text] ?? text, ...args);
128
+ }
129
+
130
+ public init(): void {
102
131
  super.init();
103
- this.validators = this.validators.filter((v) => v !== 'day').concat(['date']);
132
+ // @formio/js@5.x: this.validators is not pre-populated by the base class; guard before filtering
133
+ this.validators = (this.validators || []).filter((v) => v !== 'day').concat(['date']);
104
134
 
105
- this.component.maxDate = this.component.datePicker.maxDate;
106
- this.component.minDate = this.component.datePicker.minDate;
135
+ this.component.maxDate = this.component.datePicker?.maxDate ?? undefined;
136
+ this.component.minDate = this.component.datePicker?.minDate ?? undefined;
107
137
  this.component.suffix = null;
108
138
 
109
- this.component.fields.day.required = this.component.validate.required;
110
- this.component.fields.month.required = this.component.validate.required;
111
- this.component.fields.year.required = this.component.validate.required;
139
+ this.component.fields.day.required = this.component.validate?.required;
140
+ this.component.fields.month.required = this.component.validate?.required;
141
+ this.component.fields.year.required = this.component.validate?.required;
112
142
  this.component.fields.hour = {
113
- type: 'number', placeholder: 'HH',
114
- required: this.component.validate.required,
143
+ type: 'number',
144
+ placeholder: 'HH',
145
+ required: this.component.validate?.required,
115
146
  };
116
147
  this.component.fields.minute = {
117
- type: 'number', placeholder: 'MM',
118
- required: this.component.validate.required,
148
+ type: 'number',
149
+ placeholder: 'MM',
150
+ required: this.component.validate?.required,
119
151
  };
120
152
  }
121
153
 
122
- public setErrorClasses(elements, dirty, hasError) {
123
- // @ts-ignore
124
- super.setErrorClasses( [this.refs.hour, this.refs.minute, ...elements], dirty, hasError);
154
+ // elements typed as `any` to match the base Day.setErrorClasses(elements: any, ...) override signature
155
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
156
+ public setErrorClasses(elements: any, dirty: any, hasError: any): void {
157
+ super.setErrorClasses([this.refs.hour, this.refs.minute, ...elements], dirty, hasError);
125
158
  }
126
159
 
127
- public removeInputError(elements) {
128
- // @ts-ignore
160
+ // elements typed as `any` to match the base Component.removeInputError(elements: any) signature
161
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
162
+ public removeInputError(elements: any): void {
129
163
  super.removeInputError([this.refs.hour, this.refs.minute, ...elements]);
130
164
  }
131
165
 
132
- public render() {
166
+ public render(): string {
133
167
  return Field.prototype.render.call(this, this.renderTemplate('datetime', {
134
168
  component: this.component,
135
169
  dataValue: this.dataValue,
@@ -143,8 +177,10 @@ export default class GDSDatetimeComponent extends Day {
143
177
  }));
144
178
  }
145
179
 
146
- public getDate(value) {
147
- const defaults = [];
180
+ // value typed as `any` to match the base Day.getDate(value: any): null | string signature
181
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
182
+ public getDate(value: any): string | null {
183
+ const defaults: Array<string | number | undefined> = [];
148
184
  const [DAY, MONTH, YEAR, HOUR, MINUTE] = [0, 1, 2, 3, 4];
149
185
  const defaultValue = value || this.component.defaultValue;
150
186
 
@@ -156,35 +192,37 @@ export default class GDSDatetimeComponent extends Day {
156
192
  defaults[YEAR] = defaultDate.format('YYYY');
157
193
  defaults[HOUR] = defaultDate.format('HH');
158
194
  defaults[MINUTE] = defaultDate.format('mm');
159
- } catch (e) {
195
+ } catch {
160
196
  // ignored
161
197
  }
162
198
  }
163
199
 
164
- let day: any = this.processField('day', defaults, DAY);
165
- let month: any = this.processField('month', defaults, MONTH);
166
- let year: any = this.processField('year', defaults, YEAR);
167
- let hour: any = this.processField('hour', defaults, HOUR);
168
- let minute: any = this.processField('minute', defaults, MINUTE);
200
+ const day: number = this.processField('day', defaults, DAY);
201
+ const month: number = this.processField('month', defaults, MONTH);
202
+ const year: number = this.processField('year', defaults, YEAR);
203
+ const hour: number = this.processField('hour', defaults, HOUR);
204
+ const minute: number = this.processField('minute', defaults, MINUTE);
169
205
 
170
206
  if (!day && !month && !year && (!hour && !minute)) {
171
207
  return null;
172
208
  }
173
209
 
174
- day = day.toString().padStart(2, 0);
175
- month = month.toString().padStart(2, 0);
176
- year = year.toString().padStart(4, 0);
177
- hour = hour.toString().padStart(2, 0);
178
- minute = minute.toString().padStart(2, 0);
210
+ const dayStr = day.toString().padStart(2, '0');
211
+ const monthStr = month.toString().padStart(2, '0');
212
+ const yearStr = year.toString().padStart(4, '0');
213
+ const hourStr = hour.toString().padStart(2, '0');
214
+ const minuteStr = minute.toString().padStart(2, '0');
179
215
 
180
- const toMoment = moment(`${year}-${month}-${day} ${hour}:${minute}`, 'YYYY-MM-DD HH:mm');
216
+ const toMoment = moment(`${yearStr}-${monthStr}-${dayStr} ${hourStr}:${minuteStr}`, 'YYYY-MM-DD HH:mm');
181
217
  return toMoment.format();
182
218
  }
183
219
 
184
- public getFieldValue(name) {
220
+ // name typed as `any` to match the base Day.getFieldValue(name: any): number signature
221
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
222
+ public getFieldValue(name: any): string | null {
185
223
  if (this.dataValue && this.dataValue !== 'Invalid date') {
186
224
  try {
187
- let val = null;
225
+ let val: string | null = null;
188
226
  const date = moment(this.dataValue, 'YYYY-MM-DD HH:mm');
189
227
 
190
228
  switch (name) {
@@ -205,27 +243,27 @@ export default class GDSDatetimeComponent extends Day {
205
243
  break;
206
244
  }
207
245
  return val;
208
- } catch (e) {
246
+ } catch {
209
247
  return null;
210
248
  }
211
249
  }
212
250
  return null;
213
251
  }
214
252
 
215
- public boolValue(value) {
253
+ public boolValue(value: unknown): boolean {
216
254
  if (_.isBoolean(value)) {
217
255
  return value;
218
- }
219
- else if (_.isString(value)) {
256
+ } else if (_.isString(value)) {
220
257
  return (value.toLowerCase() === 'true');
221
- }
222
- else {
258
+ } else {
223
259
  return !!value;
224
260
  }
225
261
  }
226
- public setValueAt(index, value) {
227
- // temporary solution to avoid input reset
228
- // on invalid date.
262
+
263
+ // value typed as `any` to match the base Day.setValueAt(index: number, value: any) signature
264
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
265
+ public setValueAt(_index: number, value: any): void {
266
+ // temporary solution to avoid input reset on invalid date.
229
267
  if (!value || value === 'Invalid date') {
230
268
  return;
231
269
  }
@@ -243,51 +281,48 @@ export default class GDSDatetimeComponent extends Day {
243
281
  if (this.refs.hour) {
244
282
  this.refs.hour.value = date.format('HH');
245
283
  }
246
-
247
284
  if (this.refs.minute) {
248
285
  this.refs.minute.value = date.format('mm');
249
286
  }
250
287
  }
251
-
252
288
  }
253
289
 
254
- public getValueAt(index) {
255
- // @ts-ignore
290
+ public getValueAt(index: number): string | null {
291
+ // `date` is a public getter declared on DayComponent: get date(): string | null
256
292
  const date = this.date;
257
293
  if (date) {
258
294
  this.refs.input[index].value = date;
259
295
  return this.refs.input[index].value;
260
- }
261
- else {
296
+ } else {
262
297
  this.refs.input[index].value = '';
263
298
  return null;
264
299
  }
265
300
  }
266
301
 
267
- public normalizeValue(value) {
302
+ // value typed as `any` to match the base Component.normalizeValue(value: any): any signature
303
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
304
+ public normalizeValue(value: any): any {
268
305
  return value;
269
306
  }
270
307
 
271
- public validateRequired(setting, value) {
272
- const {day, month, year, minute, hour} = this.parts;
308
+ // setting/value typed as `any` to match the base Day.validateRequired(setting: any, value: any) signature
309
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
310
+ public validateRequired(setting: any, value: any): boolean {
311
+ const { day, month, year, minute, hour } = this.parts;
273
312
 
274
- if (this.component.validate.required && (!day || parseInt(day, 10) === 0)) {
313
+ if (this.component.validate?.required && (!day || parseInt(day, 10) === 0)) {
275
314
  return false;
276
315
  }
277
-
278
- if (this.component.validate.required && (!month || parseInt(month, 10) === 0)) {
316
+ if (this.component.validate?.required && (!month || parseInt(month, 10) === 0)) {
279
317
  return false;
280
318
  }
281
-
282
- if (this.component.validate.required && (!year || parseInt(year, 10) === 0)) {
319
+ if (this.component.validate?.required && (!year || parseInt(year, 10) === 0)) {
283
320
  return false;
284
321
  }
285
-
286
- if (this.component.validate.required && ((this.refs.minute && this.refs.minute.value === '') || !minute)) {
322
+ if (this.component.validate?.required && (this.refs.minute.value === '' || !minute)) {
287
323
  return false;
288
324
  }
289
-
290
- if (this.component.validate.required && ((this.refs.hour && this.refs.hour.value === '') || !hour)) {
325
+ if (this.component.validate?.required && (this.refs.hour.value === '' || !hour)) {
291
326
  return false;
292
327
  }
293
328
 
@@ -297,13 +332,15 @@ export default class GDSDatetimeComponent extends Day {
297
332
  return !this.isEmpty(value);
298
333
  }
299
334
 
300
- private processField(field: string, defaults: any[], fieldIndex: number) {
301
- let fieldValue = this.refs[`${field}`] ? parseInt(this.refs[`${field}`].value, 10) : undefined;
335
+ private processField(field: string, defaults: Array<string | number | undefined>, fieldIndex: number): number {
336
+ const refKey = field as keyof typeof this.refs;
337
+ const ref = this.refs[refKey];
338
+ const inputRef = ref instanceof HTMLInputElement ? ref : undefined;
339
+ let fieldValue: number | undefined = inputRef ? parseInt(inputRef.value, 10) : undefined;
302
340
  if (fieldValue === undefined || _.isNaN(fieldValue)) {
303
- fieldValue = defaults[fieldIndex] && !_.isNaN(defaults[fieldIndex]) ? defaults[fieldIndex] : 0;
341
+ fieldValue = defaults[fieldIndex] && !_.isNaN(defaults[fieldIndex]) ? Number(defaults[fieldIndex]) : 0;
304
342
  }
305
343
  return fieldValue;
306
-
307
344
  }
308
345
 
309
346
  }
@@ -1,11 +1,13 @@
1
1
  import datamap from './datamap/GDSDataMap';
2
2
  import datetime from './datetime/GDSDatetimeComponent';
3
+ import select from './select/GDSSelect';
3
4
  import selectboxes from './selectboxes/GDSCheckBoxes';
4
5
  import time from './time/GDSTimeComponent';
5
6
 
6
7
  export default {
7
8
  datamap,
8
9
  datetime,
10
+ select,
9
11
  selectboxes,
10
12
  time,
11
13
  };