@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.
- package/.github/workflows/build-and-test.yml +3 -3
- package/LICENCE.md +21 -0
- package/README.md +8 -0
- package/eslint.config.mjs +59 -0
- package/lib/components/datamap/GDSDataMap.d.ts +5 -14
- package/lib/components/datamap/GDSDataMap.d.ts.map +1 -0
- package/lib/components/datamap/GDSDataMap.js +9 -29
- package/lib/components/datetime/GDSDatetimeComponent.d.ts +43 -22
- package/lib/components/datetime/GDSDatetimeComponent.d.ts.map +1 -0
- package/lib/components/datetime/GDSDatetimeComponent.js +167 -178
- package/lib/components/index.d.ts +3 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +6 -4
- package/lib/components/select/GDSSelect.d.ts +143 -0
- package/lib/components/select/GDSSelect.d.ts.map +1 -0
- package/lib/components/select/GDSSelect.js +340 -0
- package/lib/components/selectboxes/GDSCheckBoxes.d.ts +5 -2
- package/lib/components/selectboxes/GDSCheckBoxes.d.ts.map +1 -0
- package/lib/components/selectboxes/GDSCheckBoxes.js +7 -33
- package/lib/components/time/GDSTimeComponent.d.ts +13 -10
- package/lib/components/time/GDSTimeComponent.d.ts.map +1 -0
- package/lib/components/time/GDSTimeComponent.js +59 -84
- package/lib/components/util/TimeHelper.d.ts +6 -4
- package/lib/components/util/TimeHelper.d.ts.map +1 -0
- package/lib/components/util/TimeHelper.js +13 -16
- package/lib/index.d.ts +4 -2
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2 -2
- package/lib/templates/gds/button/index.d.ts +1 -0
- package/lib/templates/gds/button/index.d.ts.map +1 -0
- package/lib/templates/gds/button/index.js +1 -1
- package/lib/templates/gds/checkbox/index.d.ts +1 -0
- package/lib/templates/gds/checkbox/index.d.ts.map +1 -0
- package/lib/templates/gds/checkbox/index.js +1 -1
- package/lib/templates/gds/columns/index.d.ts +1 -0
- package/lib/templates/gds/columns/index.d.ts.map +1 -0
- package/lib/templates/gds/columns/index.js +1 -1
- package/lib/templates/gds/component/index.d.ts +1 -0
- package/lib/templates/gds/component/index.d.ts.map +1 -0
- package/lib/templates/gds/component/index.js +1 -1
- package/lib/templates/gds/container/index.d.ts +1 -0
- package/lib/templates/gds/container/index.d.ts.map +1 -0
- package/lib/templates/gds/container/index.js +1 -1
- package/lib/templates/gds/cssClasses.d.ts +1 -0
- package/lib/templates/gds/cssClasses.d.ts.map +1 -0
- package/lib/templates/gds/datagrid/form.ejs.js +2 -2
- package/lib/templates/gds/datagrid/index.d.ts +1 -0
- package/lib/templates/gds/datagrid/index.d.ts.map +1 -0
- package/lib/templates/gds/datagrid/index.js +1 -1
- package/lib/templates/gds/datamap/index.d.ts +1 -0
- package/lib/templates/gds/datamap/index.d.ts.map +1 -0
- package/lib/templates/gds/datamap/index.js +1 -1
- package/lib/templates/gds/datetime/index.d.ts +1 -0
- package/lib/templates/gds/datetime/index.d.ts.map +1 -0
- package/lib/templates/gds/datetime/index.js +1 -1
- package/lib/templates/gds/day/index.d.ts +1 -0
- package/lib/templates/gds/day/index.d.ts.map +1 -0
- package/lib/templates/gds/day/index.js +1 -1
- package/lib/templates/gds/editgrid/index.d.ts +1 -0
- package/lib/templates/gds/editgrid/index.d.ts.map +1 -0
- package/lib/templates/gds/editgrid/index.js +1 -1
- package/lib/templates/gds/field/index.d.ts +1 -0
- package/lib/templates/gds/field/index.d.ts.map +1 -0
- package/lib/templates/gds/field/index.js +1 -1
- package/lib/templates/gds/fieldset/index.d.ts +1 -0
- package/lib/templates/gds/fieldset/index.d.ts.map +1 -0
- package/lib/templates/gds/fieldset/index.js +1 -1
- package/lib/templates/gds/file/index.d.ts +1 -0
- package/lib/templates/gds/file/index.d.ts.map +1 -0
- package/lib/templates/gds/file/index.js +1 -1
- package/lib/templates/gds/iconClass.d.ts +2 -1
- package/lib/templates/gds/iconClass.d.ts.map +1 -0
- package/lib/templates/gds/iconClass.js +3 -3
- package/lib/templates/gds/index.d.ts +3 -2
- package/lib/templates/gds/index.d.ts.map +1 -0
- package/lib/templates/gds/index.js +72 -64
- package/lib/templates/gds/input/index.d.ts +1 -0
- package/lib/templates/gds/input/index.d.ts.map +1 -0
- package/lib/templates/gds/input/index.js +1 -1
- package/lib/templates/gds/label/index.d.ts +1 -0
- package/lib/templates/gds/label/index.d.ts.map +1 -0
- package/lib/templates/gds/label/index.js +1 -1
- package/lib/templates/gds/message/index.d.ts +1 -0
- package/lib/templates/gds/message/index.d.ts.map +1 -0
- package/lib/templates/gds/message/index.js +1 -1
- package/lib/templates/gds/panel/index.d.ts +1 -0
- package/lib/templates/gds/panel/index.d.ts.map +1 -0
- package/lib/templates/gds/panel/index.js +1 -1
- package/lib/templates/gds/radio/index.d.ts +1 -0
- package/lib/templates/gds/radio/index.d.ts.map +1 -0
- package/lib/templates/gds/radio/index.js +1 -1
- package/lib/templates/gds/select/index.d.ts +1 -0
- package/lib/templates/gds/select/index.d.ts.map +1 -0
- package/lib/templates/gds/select/index.js +1 -1
- package/lib/templates/gds/selectOption/index.d.ts +1 -0
- package/lib/templates/gds/selectOption/index.d.ts.map +1 -0
- package/lib/templates/gds/selectOption/index.js +1 -1
- package/lib/templates/gds/selectboxes/index.d.ts +1 -0
- package/lib/templates/gds/selectboxes/index.d.ts.map +1 -0
- package/lib/templates/gds/selectboxes/index.js +1 -1
- package/lib/templates/gds/survey/index.d.ts +1 -0
- package/lib/templates/gds/survey/index.d.ts.map +1 -0
- package/lib/templates/gds/survey/index.js +1 -1
- package/lib/templates/gds/tab/index.d.ts +1 -0
- package/lib/templates/gds/tab/index.d.ts.map +1 -0
- package/lib/templates/gds/tab/index.js +1 -1
- package/lib/templates/gds/table/index.d.ts +1 -0
- package/lib/templates/gds/table/index.d.ts.map +1 -0
- package/lib/templates/gds/table/index.js +1 -1
- package/lib/templates/gds/template.css +27 -0
- package/lib/templates/gds/template.css.map +1 -1
- package/lib/templates/gds/time/index.d.ts +1 -0
- package/lib/templates/gds/time/index.d.ts.map +1 -0
- package/lib/templates/gds/time/index.js +1 -1
- package/lib/templates/gds/warning/index.d.ts +1 -0
- package/lib/templates/gds/warning/index.d.ts.map +1 -0
- package/lib/templates/gds/warning/index.js +1 -1
- package/lib/templates/gds/wizard/index.d.ts +1 -0
- package/lib/templates/gds/wizard/index.d.ts.map +1 -0
- package/lib/templates/gds/wizard/index.js +1 -1
- package/lib/templates/gds/wizardHeader/index.d.ts +1 -0
- package/lib/templates/gds/wizardHeader/index.d.ts.map +1 -0
- package/lib/templates/gds/wizardHeader/index.js +1 -1
- package/lib/templates/gds/wizardNav/index.d.ts +1 -0
- package/lib/templates/gds/wizardNav/index.d.ts.map +1 -0
- package/lib/templates/gds/wizardNav/index.js +1 -1
- package/lib/templates/index.d.ts +3 -2
- package/lib/templates/index.d.ts.map +1 -0
- package/lib/templates/index.js +1 -1
- package/lib/types.d.ts +37 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/package.json +14 -7
- package/src/components/datamap/GDSDataMap.ts +5 -14
- package/src/components/datetime/GDSDatetimeComponent.ts +128 -91
- package/src/components/index.ts +2 -0
- package/src/components/select/GDSSelect.spec.ts +538 -0
- package/src/components/select/GDSSelect.ts +418 -0
- package/src/components/selectboxes/GDSCheckBoxes.ts +7 -8
- package/src/components/time/GDSTimeComponent.ts +37 -27
- package/src/components/util/TimeHelper.ts +6 -5
- package/src/css.d.ts +4 -0
- package/src/templates/gds/datagrid/form.ejs +1 -2
- package/src/templates/gds/iconClass.ts +1 -1
- package/src/templates/gds/index.ts +43 -33
- package/src/templates/gds/template.scss +48 -1
- package/src/types.ts +56 -0
- package/tsconfig.json +21 -5
- package/webpack.config.js +1 -1
- package/tslint.json +0 -22
|
@@ -1,34 +1,54 @@
|
|
|
1
|
-
import {Components} from '
|
|
2
|
-
import FormioUtils from '
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
106
|
-
this.component.minDate = this.component.datePicker
|
|
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
|
|
110
|
-
this.component.fields.month.required = this.component.validate
|
|
111
|
-
this.component.fields.year.required = this.component.validate
|
|
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',
|
|
114
|
-
|
|
143
|
+
type: 'number',
|
|
144
|
+
placeholder: 'HH',
|
|
145
|
+
required: this.component.validate?.required,
|
|
115
146
|
};
|
|
116
147
|
this.component.fields.minute = {
|
|
117
|
-
type: 'number',
|
|
118
|
-
|
|
148
|
+
type: 'number',
|
|
149
|
+
placeholder: 'MM',
|
|
150
|
+
required: this.component.validate?.required,
|
|
119
151
|
};
|
|
120
152
|
}
|
|
121
153
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
128
|
-
|
|
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
|
-
|
|
147
|
-
|
|
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
|
|
195
|
+
} catch {
|
|
160
196
|
// ignored
|
|
161
197
|
}
|
|
162
198
|
}
|
|
163
199
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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(`${
|
|
216
|
+
const toMoment = moment(`${yearStr}-${monthStr}-${dayStr} ${hourStr}:${minuteStr}`, 'YYYY-MM-DD HH:mm');
|
|
181
217
|
return toMoment.format();
|
|
182
218
|
}
|
|
183
219
|
|
|
184
|
-
|
|
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
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
272
|
-
|
|
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
|
|
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:
|
|
301
|
-
|
|
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
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -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
|
};
|