@aemforms/af-core 0.22.17 → 0.22.19
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/lib/BaseNode.d.ts +13 -0
- package/lib/BaseNode.js +40 -8
- package/lib/CheckboxGroup.js +3 -0
- package/lib/Container.d.ts +16 -308
- package/lib/Container.js +34 -17
- package/lib/Field.d.ts +35 -8
- package/lib/Field.js +224 -26
- package/lib/Fieldset.d.ts +0 -10
- package/lib/Fieldset.js +3 -42
- package/lib/FileObject.d.ts +3 -2
- package/lib/FileObject.js +6 -3
- package/lib/FileUpload.d.ts +2 -1
- package/lib/FileUpload.js +4 -1
- package/lib/Form.d.ts +36 -280
- package/lib/Form.js +25 -3
- package/lib/FormInstance.js +14 -6
- package/lib/InstanceManager.d.ts +16 -0
- package/lib/InstanceManager.js +53 -0
- package/lib/Scriptable.d.ts +1 -1
- package/lib/Scriptable.js +7 -7
- package/lib/controller/Controller.d.ts +32 -0
- package/lib/controller/Controller.js +42 -1
- package/lib/data/DataGroup.js +5 -1
- package/lib/data/DataValue.d.ts +1 -1
- package/lib/data/DataValue.js +4 -0
- package/lib/rules/FunctionRuntime.js +6 -0
- package/lib/types/Json.d.ts +6 -0
- package/lib/types/Model.d.ts +22 -7
- package/lib/utils/Fetch.d.ts +7 -0
- package/lib/utils/Fetch.js +67 -9
- package/lib/utils/FormCreationUtils.d.ts +11 -0
- package/lib/utils/FormCreationUtils.js +83 -0
- package/lib/utils/FormUtils.js +8 -5
- package/lib/utils/JsonUtils.d.ts +1 -0
- package/lib/utils/JsonUtils.js +15 -1
- package/lib/utils/ValidationUtils.js +14 -0
- package/package.json +2 -2
package/lib/Field.d.ts
CHANGED
|
@@ -2,9 +2,6 @@ import { ConstraintsMessages, ContainerModel, FieldJson, FieldModel, FormModel,
|
|
|
2
2
|
import Scriptable from './Scriptable';
|
|
3
3
|
import DataValue from './data/DataValue';
|
|
4
4
|
import DataGroup from './data/DataGroup';
|
|
5
|
-
/**
|
|
6
|
-
* Defines a form object field which implements {@link FieldModel | field model} interface
|
|
7
|
-
*/
|
|
8
5
|
declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
9
6
|
/**
|
|
10
7
|
* @param params
|
|
@@ -62,8 +59,15 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
62
59
|
get editValue(): any;
|
|
63
60
|
get displayValue(): any;
|
|
64
61
|
protected getDataNodeValue(typedValue: any): any;
|
|
62
|
+
private updateDataNodeAndTypedValue;
|
|
65
63
|
get value(): any;
|
|
66
64
|
set value(v: any);
|
|
65
|
+
/**
|
|
66
|
+
* @summary reset the value of the current field to its default
|
|
67
|
+
* @method reset
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
reset(): void;
|
|
67
71
|
protected _updateRuleNodeReference(value: any): void;
|
|
68
72
|
protected getInternalType(): string | undefined;
|
|
69
73
|
valueOf(): any;
|
|
@@ -73,6 +77,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
73
77
|
* @param constraint
|
|
74
78
|
*/
|
|
75
79
|
getErrorMessage(constraint: keyof (ConstraintsMessages)): string;
|
|
80
|
+
get errorMessage(): string | undefined;
|
|
81
|
+
get screenReaderText(): string | undefined;
|
|
76
82
|
/**
|
|
77
83
|
*
|
|
78
84
|
* @private
|
|
@@ -176,7 +182,19 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
176
182
|
/**
|
|
177
183
|
* returns the format constraint
|
|
178
184
|
*/
|
|
179
|
-
get format(): string;
|
|
185
|
+
get format(): string | undefined;
|
|
186
|
+
get enforceEnum(): boolean | undefined;
|
|
187
|
+
get tooltip(): string | undefined;
|
|
188
|
+
get maxLength(): number | undefined;
|
|
189
|
+
get minLength(): number | undefined;
|
|
190
|
+
get pattern(): string | undefined;
|
|
191
|
+
get step(): number | undefined;
|
|
192
|
+
get exclusiveMinimum(): number | undefined;
|
|
193
|
+
set exclusiveMinimum(eM: number | undefined);
|
|
194
|
+
get exclusiveMaximum(): number | undefined;
|
|
195
|
+
set exclusiveMaximum(eM: number | undefined);
|
|
196
|
+
get default(): any;
|
|
197
|
+
private isNotEmpty;
|
|
180
198
|
/**
|
|
181
199
|
* @private
|
|
182
200
|
*/
|
|
@@ -196,8 +214,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
196
214
|
editValue: any;
|
|
197
215
|
displayValue: any;
|
|
198
216
|
description?: string | undefined;
|
|
199
|
-
rules
|
|
200
|
-
events
|
|
217
|
+
rules: import("./types").Items<string> & {};
|
|
218
|
+
events: import("./types").Items<string | string[] | undefined> & {};
|
|
201
219
|
enumNames?: string[] | undefined;
|
|
202
220
|
enum?: any[] | undefined;
|
|
203
221
|
accept?: string[] | undefined;
|
|
@@ -209,6 +227,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
209
227
|
maxLength?: number | undefined;
|
|
210
228
|
maximum?: number | undefined;
|
|
211
229
|
maxItems?: number | undefined;
|
|
230
|
+
minOccur?: number | undefined;
|
|
231
|
+
maxOccur?: number | undefined;
|
|
212
232
|
minLength?: number | undefined;
|
|
213
233
|
minimum?: number | undefined;
|
|
214
234
|
minItems?: number | undefined;
|
|
@@ -227,9 +247,13 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
227
247
|
constraintMessages?: ConstraintsMessages | undefined;
|
|
228
248
|
fieldType?: string | undefined;
|
|
229
249
|
errorMessage?: string | undefined;
|
|
230
|
-
properties
|
|
250
|
+
properties: {
|
|
231
251
|
[key: string]: any;
|
|
232
|
-
}
|
|
252
|
+
};
|
|
253
|
+
repeatable?: boolean | undefined;
|
|
254
|
+
screenReaderText?: string | undefined;
|
|
255
|
+
tooltip?: string | undefined;
|
|
256
|
+
altText?: string | undefined;
|
|
233
257
|
placeholder?: string | undefined;
|
|
234
258
|
readOnly?: boolean | undefined;
|
|
235
259
|
valid?: boolean | undefined;
|
|
@@ -238,6 +262,9 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
238
262
|
displayFormat?: string | undefined;
|
|
239
263
|
editFormat?: string | undefined;
|
|
240
264
|
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
265
|
+
index: number;
|
|
266
|
+
parent: undefined;
|
|
267
|
+
qualifiedName: any;
|
|
241
268
|
id: string;
|
|
242
269
|
};
|
|
243
270
|
}
|
package/lib/Field.js
CHANGED
|
@@ -28,6 +28,7 @@ const af_formatters_1 = require("@aemforms/af-formatters");
|
|
|
28
28
|
/**
|
|
29
29
|
* Defines a form object field which implements {@link FieldModel | field model} interface
|
|
30
30
|
*/
|
|
31
|
+
const validTypes = ['string', 'number', 'boolean', 'file', 'string[]', 'number[]', 'boolean[]', 'file[]', 'array', 'object'];
|
|
31
32
|
class Field extends Scriptable_1.default {
|
|
32
33
|
/**
|
|
33
34
|
* @param params
|
|
@@ -73,10 +74,31 @@ class Field extends Scriptable_1.default {
|
|
|
73
74
|
*/
|
|
74
75
|
_getFallbackType() {
|
|
75
76
|
const type = this._jsonModel.type;
|
|
76
|
-
|
|
77
|
+
let finalType = type;
|
|
78
|
+
if (typeof type !== 'string' || validTypes.indexOf(type) === -1) {
|
|
77
79
|
const _enum = this.enum;
|
|
78
|
-
|
|
80
|
+
finalType = typeof (_enum === null || _enum === void 0 ? void 0 : _enum[0]);
|
|
81
|
+
if (finalType === 'undefined' && typeof this._jsonModel.default !== 'undefined') {
|
|
82
|
+
if (this._jsonModel.default instanceof Array && this._jsonModel.default.length > 0) {
|
|
83
|
+
finalType = `${typeof (this._jsonModel.default[0])}[]`;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
finalType = typeof (this._jsonModel.default);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (finalType.indexOf('undefined') === 0) {
|
|
90
|
+
const typeMappings = {
|
|
91
|
+
'text-input': 'string',
|
|
92
|
+
'number-input': 'number',
|
|
93
|
+
'date-input': 'string',
|
|
94
|
+
'plain-text': 'string',
|
|
95
|
+
'image': 'string',
|
|
96
|
+
'checkbox': 'boolean'
|
|
97
|
+
};
|
|
98
|
+
finalType = typeMappings[this.fieldType];
|
|
99
|
+
}
|
|
79
100
|
}
|
|
101
|
+
return finalType;
|
|
80
102
|
}
|
|
81
103
|
_applyDefaults() {
|
|
82
104
|
Object.entries(this._getDefaults()).map(([key, value]) => {
|
|
@@ -86,12 +108,23 @@ class Field extends Scriptable_1.default {
|
|
|
86
108
|
this._jsonModel[key] = value;
|
|
87
109
|
}
|
|
88
110
|
});
|
|
111
|
+
const type = this._jsonModel.type;
|
|
112
|
+
if (typeof type !== 'string' || validTypes.indexOf(type) === -1) {
|
|
113
|
+
this._jsonModel.type = this._getFallbackType();
|
|
114
|
+
}
|
|
115
|
+
if (['plain-text', 'image'].indexOf(this.fieldType) === -1) {
|
|
116
|
+
this._jsonModel.value = undefined;
|
|
117
|
+
}
|
|
89
118
|
const value = this._jsonModel.value;
|
|
90
119
|
if (value === undefined) {
|
|
91
120
|
const typedRes = ValidationUtils_1.Constraints.type(this.getInternalType() || 'string', this._jsonModel.default);
|
|
92
121
|
this._jsonModel.value = typedRes.value;
|
|
93
122
|
}
|
|
123
|
+
if (this._jsonModel.type !== 'string') {
|
|
124
|
+
this._jsonModel.emptyValue = undefined;
|
|
125
|
+
}
|
|
94
126
|
if (this._jsonModel.fieldType === undefined) {
|
|
127
|
+
this.form.logger.error('fieldType property is mandatory. Please ensure all the fields have a fieldType');
|
|
95
128
|
//@ts-ignore
|
|
96
129
|
if (this._jsonModel.viewType) {
|
|
97
130
|
//@ts-ignore
|
|
@@ -114,7 +147,39 @@ class Field extends Scriptable_1.default {
|
|
|
114
147
|
this._jsonModel.enum = [true, false];
|
|
115
148
|
}
|
|
116
149
|
}
|
|
117
|
-
|
|
150
|
+
else {
|
|
151
|
+
if (typeof this._jsonModel.enumNames === 'undefined') {
|
|
152
|
+
this._jsonModel.enumNames = this._jsonModel.enum.map(_ => _.toString());
|
|
153
|
+
}
|
|
154
|
+
while (this._jsonModel.enumNames.length < this._jsonModel.enum.length) {
|
|
155
|
+
//@ts-ignore
|
|
156
|
+
this._jsonModel.enumNames.push(this._jsonModel.enum[this._jsonModel.enumNames.length].toString());
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (this._jsonModel.type !== 'string') {
|
|
160
|
+
this._jsonModel.format = undefined;
|
|
161
|
+
this._jsonModel.pattern = undefined;
|
|
162
|
+
this._jsonModel.minLength = undefined;
|
|
163
|
+
this._jsonModel.maxLength = undefined;
|
|
164
|
+
}
|
|
165
|
+
else if (this._jsonModel.fieldType === 'date-input') {
|
|
166
|
+
this._jsonModel.format = 'date';
|
|
167
|
+
}
|
|
168
|
+
if (this._jsonModel.type !== 'number' && this._jsonModel.format !== 'date') {
|
|
169
|
+
this._jsonModel.step = undefined;
|
|
170
|
+
this._jsonModel.minimum = undefined;
|
|
171
|
+
this._jsonModel.maximum = undefined;
|
|
172
|
+
this._jsonModel.exclusiveMinimum = undefined;
|
|
173
|
+
this._jsonModel.exclusiveMaximum = undefined;
|
|
174
|
+
}
|
|
175
|
+
['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'].forEach(c => {
|
|
176
|
+
//@ts-ignore
|
|
177
|
+
if (typeof this._jsonModel[c] !== this._jsonModel.type) {
|
|
178
|
+
//@ts-ignore
|
|
179
|
+
this._jsonModel[c] = undefined;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
if (typeof this._jsonModel.step !== 'number') {
|
|
118
183
|
this._jsonModel.step = undefined;
|
|
119
184
|
}
|
|
120
185
|
}
|
|
@@ -176,16 +241,24 @@ class Field extends Scriptable_1.default {
|
|
|
176
241
|
this._setProperty('required', r);
|
|
177
242
|
}
|
|
178
243
|
get maximum() {
|
|
179
|
-
|
|
244
|
+
if (this.type === 'number' || this.format === 'date') {
|
|
245
|
+
return this._jsonModel.maximum;
|
|
246
|
+
}
|
|
180
247
|
}
|
|
181
248
|
set maximum(m) {
|
|
182
|
-
this.
|
|
249
|
+
if (this.type === 'number' || this.format === 'date') {
|
|
250
|
+
this._setProperty('maximum', m);
|
|
251
|
+
}
|
|
183
252
|
}
|
|
184
253
|
get minimum() {
|
|
185
|
-
|
|
254
|
+
if (this.type === 'number' || this.format === 'date') {
|
|
255
|
+
return this._jsonModel.minimum;
|
|
256
|
+
}
|
|
186
257
|
}
|
|
187
258
|
set minimum(m) {
|
|
188
|
-
this.
|
|
259
|
+
if (this.type === 'number' || this.format === 'date') {
|
|
260
|
+
this._setProperty('minimum', m);
|
|
261
|
+
}
|
|
189
262
|
}
|
|
190
263
|
/**
|
|
191
264
|
* returns whether the value is empty. Empty value is either a '', undefined or null
|
|
@@ -196,7 +269,7 @@ class Field extends Scriptable_1.default {
|
|
|
196
269
|
}
|
|
197
270
|
get editValue() {
|
|
198
271
|
const format = this.editFormat;
|
|
199
|
-
if (this.format == 'date' && this.value
|
|
272
|
+
if (this.format == 'date' && this.isNotEmpty(this.value) && this.valid !== false) {
|
|
200
273
|
return (0, af_formatters_1.formatDate)(new Date(this.value), this.language, format);
|
|
201
274
|
}
|
|
202
275
|
else {
|
|
@@ -205,7 +278,7 @@ class Field extends Scriptable_1.default {
|
|
|
205
278
|
}
|
|
206
279
|
get displayValue() {
|
|
207
280
|
const format = this.displayFormat;
|
|
208
|
-
if (this.format == 'date' && this.value
|
|
281
|
+
if (this.format == 'date' && this.isNotEmpty(this.value) && this.valid !== false) {
|
|
209
282
|
return (0, af_formatters_1.formatDate)(new Date(this.value), this.language, format);
|
|
210
283
|
}
|
|
211
284
|
else {
|
|
@@ -215,6 +288,23 @@ class Field extends Scriptable_1.default {
|
|
|
215
288
|
getDataNodeValue(typedValue) {
|
|
216
289
|
return this.isEmpty() ? this.emptyValue : typedValue;
|
|
217
290
|
}
|
|
291
|
+
updateDataNodeAndTypedValue(val) {
|
|
292
|
+
const dataNode = this.getDataNode();
|
|
293
|
+
if (BaseNode_1.staticFields.indexOf(this.fieldType) > -1 && typeof dataNode !== 'undefined') {
|
|
294
|
+
// if a static field is bound to data node it can not be updated.
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const Constraints = this._getConstraintObject();
|
|
298
|
+
const typeRes = Constraints.type(this.getInternalType() || 'string', val);
|
|
299
|
+
const changes = this._setProperty('value', typeRes.value, false);
|
|
300
|
+
if (changes.length > 0) {
|
|
301
|
+
this._updateRuleNodeReference(typeRes.value);
|
|
302
|
+
if (typeof dataNode !== 'undefined') {
|
|
303
|
+
dataNode.setValue(this.getDataNodeValue(this._jsonModel.value), this._jsonModel.value, this);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return changes;
|
|
307
|
+
}
|
|
218
308
|
get value() {
|
|
219
309
|
if (this._jsonModel.value === undefined) {
|
|
220
310
|
return null;
|
|
@@ -224,21 +314,15 @@ class Field extends Scriptable_1.default {
|
|
|
224
314
|
}
|
|
225
315
|
}
|
|
226
316
|
set value(v) {
|
|
227
|
-
const
|
|
228
|
-
const typeRes = Constraints.type(this.getInternalType() || 'string', v);
|
|
229
|
-
const changes = this._setProperty('value', typeRes.value, false);
|
|
317
|
+
const changes = this.updateDataNodeAndTypedValue(v);
|
|
230
318
|
let uniqueRes = { valid: true };
|
|
231
|
-
if (changes.length > 0) {
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
if (typeof dataNode !== 'undefined') {
|
|
235
|
-
dataNode.setValue(this.getDataNodeValue(this._jsonModel.value), this._jsonModel.value, this);
|
|
236
|
-
}
|
|
319
|
+
if ((changes === null || changes === void 0 ? void 0 : changes.length) > 0) {
|
|
320
|
+
let updates = {};
|
|
321
|
+
const typeRes = ValidationUtils_1.Constraints.type(this.getInternalType() || 'string', v);
|
|
237
322
|
if (this.parent.uniqueItems && this.parent.type === 'array') {
|
|
238
323
|
// @ts-ignore
|
|
239
|
-
uniqueRes = Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
|
|
324
|
+
uniqueRes = ValidationUtils_1.Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
|
|
240
325
|
}
|
|
241
|
-
let updates;
|
|
242
326
|
if (typeRes.valid && uniqueRes.valid) {
|
|
243
327
|
updates = this.evaluateConstraints();
|
|
244
328
|
}
|
|
@@ -256,6 +340,28 @@ class Field extends Scriptable_1.default {
|
|
|
256
340
|
this.dispatch(changeAction);
|
|
257
341
|
}
|
|
258
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* @summary reset the value of the current field to its default
|
|
345
|
+
* @method reset
|
|
346
|
+
* @private
|
|
347
|
+
*/
|
|
348
|
+
reset() {
|
|
349
|
+
// update the default value as typed value and also its data node
|
|
350
|
+
const changes = this.updateDataNodeAndTypedValue(this.default); // set the value to default value during reset
|
|
351
|
+
// if there are changes, trigger change event and reset the validation state (ie errorMessage and valid state)
|
|
352
|
+
if (changes.length > 0) {
|
|
353
|
+
// disable all field validations during field reset.
|
|
354
|
+
// reset to default state (ie) field is valid and error message set as empty
|
|
355
|
+
const validationStateChanges = {
|
|
356
|
+
'valid': undefined,
|
|
357
|
+
'errorMessage': ''
|
|
358
|
+
};
|
|
359
|
+
// only if there are changes, update would contain valid and errorMessage
|
|
360
|
+
const updates = this._applyUpdates(['valid', 'errorMessage'], validationStateChanges);
|
|
361
|
+
const changeAction = new controller_1.Change({ changes: changes.concat(Object.values(updates)) });
|
|
362
|
+
this.dispatch(changeAction);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
259
365
|
_updateRuleNodeReference(value) {
|
|
260
366
|
var _a;
|
|
261
367
|
if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
|
|
@@ -299,6 +405,12 @@ class Field extends Scriptable_1.default {
|
|
|
299
405
|
var _a;
|
|
300
406
|
return ((_a = this._jsonModel.constraintMessages) === null || _a === void 0 ? void 0 : _a[constraint]) || '';
|
|
301
407
|
}
|
|
408
|
+
get errorMessage() {
|
|
409
|
+
return this._jsonModel.errorMessage;
|
|
410
|
+
}
|
|
411
|
+
get screenReaderText() {
|
|
412
|
+
return this._jsonModel.screenReaderText;
|
|
413
|
+
}
|
|
302
414
|
/**
|
|
303
415
|
*
|
|
304
416
|
* @private
|
|
@@ -388,7 +500,65 @@ class Field extends Scriptable_1.default {
|
|
|
388
500
|
* returns the format constraint
|
|
389
501
|
*/
|
|
390
502
|
get format() {
|
|
391
|
-
|
|
503
|
+
if (typeof this._jsonModel.format === 'undefined') {
|
|
504
|
+
if (this.type === 'string') {
|
|
505
|
+
switch (this.fieldType) {
|
|
506
|
+
case 'date-input':
|
|
507
|
+
this._jsonModel.format = 'date';
|
|
508
|
+
break;
|
|
509
|
+
case 'file-input':
|
|
510
|
+
this._jsonModel.format = 'data-url';
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return this._jsonModel.format;
|
|
516
|
+
}
|
|
517
|
+
get enforceEnum() {
|
|
518
|
+
return this._jsonModel.enforceEnum;
|
|
519
|
+
}
|
|
520
|
+
get tooltip() {
|
|
521
|
+
return this._jsonModel.tooltip;
|
|
522
|
+
}
|
|
523
|
+
get maxLength() {
|
|
524
|
+
return this._jsonModel.maxLength;
|
|
525
|
+
}
|
|
526
|
+
get minLength() {
|
|
527
|
+
return this._jsonModel.minLength;
|
|
528
|
+
}
|
|
529
|
+
get pattern() {
|
|
530
|
+
return this._jsonModel.pattern;
|
|
531
|
+
}
|
|
532
|
+
get step() {
|
|
533
|
+
if (this.type === 'number' || this.format === 'date') {
|
|
534
|
+
return this._jsonModel.step;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
get exclusiveMinimum() {
|
|
538
|
+
if (this.type === 'number' || this.format === 'date') {
|
|
539
|
+
return this._jsonModel.exclusiveMinimum;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
set exclusiveMinimum(eM) {
|
|
543
|
+
if (this.type === 'number' || this.format === 'date') {
|
|
544
|
+
this._jsonModel.exclusiveMinimum = eM;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
get exclusiveMaximum() {
|
|
548
|
+
if (this.type === 'number' || this.format === 'date') {
|
|
549
|
+
return this._jsonModel.exclusiveMaximum;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
set exclusiveMaximum(eM) {
|
|
553
|
+
if (this.type === 'number' || this.format === 'date') {
|
|
554
|
+
this._jsonModel.exclusiveMaximum = eM;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
get default() {
|
|
558
|
+
return this._jsonModel.default;
|
|
559
|
+
}
|
|
560
|
+
isNotEmpty(value) {
|
|
561
|
+
return value != null && value !== '';
|
|
392
562
|
}
|
|
393
563
|
/**
|
|
394
564
|
* @private
|
|
@@ -405,9 +575,10 @@ class Field extends Scriptable_1.default {
|
|
|
405
575
|
(this.isArrayType() && this.required ? value.length > 0 : true);
|
|
406
576
|
constraint = 'required';
|
|
407
577
|
}
|
|
408
|
-
if (valid &&
|
|
578
|
+
if (valid && this.isNotEmpty(value)) {
|
|
409
579
|
const invalidConstraint = supportedConstraints.find(key => {
|
|
410
|
-
|
|
580
|
+
// @ts-ignore
|
|
581
|
+
if (key in elem && elem[key] !== undefined) {
|
|
411
582
|
// @ts-ignore
|
|
412
583
|
const restriction = elem[key];
|
|
413
584
|
// @ts-ignore
|
|
@@ -494,17 +665,20 @@ class Field extends Scriptable_1.default {
|
|
|
494
665
|
* @private
|
|
495
666
|
*/
|
|
496
667
|
defaultDataModel(name) {
|
|
497
|
-
|
|
668
|
+
const value = BaseNode_1.staticFields.indexOf(this.fieldType) > -1 ? undefined : this.getDataNodeValue(this._jsonModel.value);
|
|
669
|
+
return new DataValue_1.default(name, value, this.type || 'string');
|
|
498
670
|
}
|
|
499
671
|
getState() {
|
|
500
672
|
return Object.assign(Object.assign({}, super.getState()), { editValue: this.editValue, displayValue: this.displayValue });
|
|
501
673
|
}
|
|
502
674
|
}
|
|
503
675
|
__decorate([
|
|
504
|
-
(0, BaseNode_1.dependencyTracked)()
|
|
676
|
+
(0, BaseNode_1.dependencyTracked)(),
|
|
677
|
+
(0, BaseNode_1.exclude)('button', 'image', 'plain-text')
|
|
505
678
|
], Field.prototype, "readOnly", null);
|
|
506
679
|
__decorate([
|
|
507
|
-
(0, BaseNode_1.dependencyTracked)()
|
|
680
|
+
(0, BaseNode_1.dependencyTracked)(),
|
|
681
|
+
(0, BaseNode_1.exclude)('button', 'image', 'plain-text')
|
|
508
682
|
], Field.prototype, "enabled", null);
|
|
509
683
|
__decorate([
|
|
510
684
|
(0, BaseNode_1.dependencyTracked)()
|
|
@@ -518,7 +692,31 @@ __decorate([
|
|
|
518
692
|
__decorate([
|
|
519
693
|
(0, BaseNode_1.dependencyTracked)()
|
|
520
694
|
], Field.prototype, "required", null);
|
|
695
|
+
__decorate([
|
|
696
|
+
(0, BaseNode_1.include)('date-input', 'number-input')
|
|
697
|
+
], Field.prototype, "editValue", null);
|
|
698
|
+
__decorate([
|
|
699
|
+
(0, BaseNode_1.include)('date-input', 'number-input')
|
|
700
|
+
], Field.prototype, "displayValue", null);
|
|
521
701
|
__decorate([
|
|
522
702
|
(0, BaseNode_1.dependencyTracked)()
|
|
523
703
|
], Field.prototype, "value", null);
|
|
704
|
+
__decorate([
|
|
705
|
+
(0, BaseNode_1.include)('text-input', 'date-input', 'file-input')
|
|
706
|
+
], Field.prototype, "format", null);
|
|
707
|
+
__decorate([
|
|
708
|
+
(0, BaseNode_1.include)('text-input')
|
|
709
|
+
], Field.prototype, "maxLength", null);
|
|
710
|
+
__decorate([
|
|
711
|
+
(0, BaseNode_1.include)('text-input')
|
|
712
|
+
], Field.prototype, "minLength", null);
|
|
713
|
+
__decorate([
|
|
714
|
+
(0, BaseNode_1.include)('text-input')
|
|
715
|
+
], Field.prototype, "pattern", null);
|
|
716
|
+
__decorate([
|
|
717
|
+
(0, BaseNode_1.dependencyTracked)()
|
|
718
|
+
], Field.prototype, "exclusiveMinimum", null);
|
|
719
|
+
__decorate([
|
|
720
|
+
(0, BaseNode_1.dependencyTracked)()
|
|
721
|
+
], Field.prototype, "exclusiveMaximum", null);
|
|
524
722
|
exports.default = Field;
|
package/lib/Fieldset.d.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import Container from './Container';
|
|
2
2
|
import { ContainerModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormModel } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a child model inside the given parent
|
|
5
|
-
* @param child
|
|
6
|
-
* @param options
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
export declare const createChild: (child: FieldsetJson | FieldJson, options: {
|
|
10
|
-
form: FormModel;
|
|
11
|
-
parent: ContainerModel;
|
|
12
|
-
}) => FieldModel | FieldsetModel;
|
|
13
3
|
/**
|
|
14
4
|
* Defines a field set class which extends from {@link Container | container}
|
|
15
5
|
*/
|
package/lib/Fieldset.js
CHANGED
|
@@ -10,48 +10,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.Fieldset =
|
|
13
|
+
exports.Fieldset = void 0;
|
|
14
14
|
const Container_1 = __importDefault(require("./Container"));
|
|
15
|
-
const Field_1 = __importDefault(require("./Field"));
|
|
16
|
-
const FileUpload_1 = __importDefault(require("./FileUpload"));
|
|
17
|
-
const JsonUtils_1 = require("./utils/JsonUtils");
|
|
18
15
|
const controller_1 = require("./controller");
|
|
19
|
-
const
|
|
20
|
-
const CheckboxGroup_1 = __importDefault(require("./CheckboxGroup"));
|
|
21
|
-
const DateField_1 = __importDefault(require("./DateField"));
|
|
22
|
-
/**
|
|
23
|
-
* Creates a child model inside the given parent
|
|
24
|
-
* @param child
|
|
25
|
-
* @param options
|
|
26
|
-
* @private
|
|
27
|
-
*/
|
|
28
|
-
const createChild = (child, options) => {
|
|
29
|
-
let retVal;
|
|
30
|
-
if ('items' in child) {
|
|
31
|
-
retVal = new Fieldset(child, options);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
if ((0, JsonUtils_1.isFile)(child) || child.fieldType === 'file-input') {
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
retVal = new FileUpload_1.default(child, options);
|
|
37
|
-
}
|
|
38
|
-
else if ((0, JsonUtils_1.isCheckbox)(child)) {
|
|
39
|
-
retVal = new Checkbox_1.default(child, options);
|
|
40
|
-
}
|
|
41
|
-
else if ((0, JsonUtils_1.isCheckboxGroup)(child)) {
|
|
42
|
-
retVal = new CheckboxGroup_1.default(child, options);
|
|
43
|
-
}
|
|
44
|
-
else if ((0, JsonUtils_1.isDateField)(child)) {
|
|
45
|
-
retVal = new DateField_1.default(child, options);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
retVal = new Field_1.default(child, options);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
options.form.fieldAdded(retVal);
|
|
52
|
-
return retVal;
|
|
53
|
-
};
|
|
54
|
-
exports.createChild = createChild;
|
|
16
|
+
const FormCreationUtils_1 = require("./utils/FormCreationUtils");
|
|
55
17
|
const defaults = {
|
|
56
18
|
visible: true
|
|
57
19
|
};
|
|
@@ -89,10 +51,9 @@ class Fieldset extends Container_1.default {
|
|
|
89
51
|
}
|
|
90
52
|
return undefined;
|
|
91
53
|
}
|
|
92
|
-
// @ts-ignore
|
|
93
54
|
_createChild(child, options) {
|
|
94
55
|
const { parent = this } = options;
|
|
95
|
-
return (0,
|
|
56
|
+
return (0, FormCreationUtils_1.createChild)(child, { form: this.form, parent: parent });
|
|
96
57
|
}
|
|
97
58
|
get items() {
|
|
98
59
|
return super.items;
|
package/lib/FileObject.d.ts
CHANGED
|
@@ -4,14 +4,15 @@ import { IFileObject } from './types';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare class FileObject implements IFileObject {
|
|
6
6
|
data: any;
|
|
7
|
-
|
|
7
|
+
mediaType: string;
|
|
8
8
|
name: string;
|
|
9
9
|
size: number;
|
|
10
10
|
constructor(init?: Partial<FileObject>);
|
|
11
|
+
get type(): string;
|
|
11
12
|
toJSON(): {
|
|
12
13
|
name: string;
|
|
13
14
|
size: number;
|
|
14
|
-
|
|
15
|
+
mediaType: string;
|
|
15
16
|
data: any;
|
|
16
17
|
};
|
|
17
18
|
equals(obj: IFileObject): boolean;
|
package/lib/FileObject.js
CHANGED
|
@@ -13,22 +13,25 @@ exports.FileObject = void 0;
|
|
|
13
13
|
*/
|
|
14
14
|
class FileObject {
|
|
15
15
|
constructor(init) {
|
|
16
|
-
this.
|
|
16
|
+
this.mediaType = 'application/octet-stream';
|
|
17
17
|
this.name = 'unknown';
|
|
18
18
|
this.size = 0;
|
|
19
19
|
Object.assign(this, init);
|
|
20
20
|
}
|
|
21
|
+
get type() {
|
|
22
|
+
return this.mediaType;
|
|
23
|
+
}
|
|
21
24
|
toJSON() {
|
|
22
25
|
return {
|
|
23
26
|
'name': this.name,
|
|
24
27
|
'size': this.size,
|
|
25
|
-
'
|
|
28
|
+
'mediaType': this.mediaType,
|
|
26
29
|
'data': this.data.toString()
|
|
27
30
|
};
|
|
28
31
|
}
|
|
29
32
|
equals(obj) {
|
|
30
33
|
return (this.data === obj.data &&
|
|
31
|
-
this.
|
|
34
|
+
this.mediaType === obj.mediaType &&
|
|
32
35
|
this.name === obj.name &&
|
|
33
36
|
this.size === obj.size);
|
|
34
37
|
}
|
package/lib/FileUpload.d.ts
CHANGED
|
@@ -8,11 +8,12 @@ declare class FileUpload extends Field implements FieldModel {
|
|
|
8
8
|
protected _getDefaults(): {
|
|
9
9
|
accept: string[];
|
|
10
10
|
maxFileSize: string;
|
|
11
|
-
type: string;
|
|
12
11
|
readOnly: boolean;
|
|
13
12
|
enabled: boolean;
|
|
14
13
|
visible: boolean;
|
|
14
|
+
type: string | undefined;
|
|
15
15
|
};
|
|
16
|
+
protected _getFallbackType(): string | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* Returns the max file size in bytes as per IEC specification
|
|
18
19
|
*/
|
package/lib/FileUpload.js
CHANGED
|
@@ -56,7 +56,10 @@ function processFile(file) {
|
|
|
56
56
|
class FileUpload extends Field_1.default {
|
|
57
57
|
//private _files: FileObject[];
|
|
58
58
|
_getDefaults() {
|
|
59
|
-
return Object.assign(Object.assign({}, super._getDefaults()), { accept: ['audio/*', 'video/*', 'image/*', 'text/*', 'application/pdf'], maxFileSize: '2MB'
|
|
59
|
+
return Object.assign(Object.assign({}, super._getDefaults()), { accept: ['audio/*', 'video/*', 'image/*', 'text/*', 'application/pdf'], maxFileSize: '2MB' });
|
|
60
|
+
}
|
|
61
|
+
_getFallbackType() {
|
|
62
|
+
return 'file';
|
|
60
63
|
}
|
|
61
64
|
/**
|
|
62
65
|
* Returns the max file size in bytes as per IEC specification
|