@aemforms/af-core 0.22.18 → 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 +2 -0
- package/lib/BaseNode.js +4 -0
- package/lib/Container.d.ts +8 -107
- package/lib/Container.js +28 -14
- package/lib/Field.d.ts +11 -0
- package/lib/Field.js +48 -16
- package/lib/Fieldset.d.ts +0 -10
- package/lib/Fieldset.js +3 -42
- package/lib/Form.d.ts +25 -108
- 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.js +3 -3
- 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 +3 -0
- package/lib/types/Model.d.ts +15 -1
- 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/JsonUtils.d.ts +1 -0
- package/lib/utils/JsonUtils.js +15 -1
- package/package.json +2 -2
package/lib/BaseNode.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
40
40
|
parent: ContainerModel;
|
|
41
41
|
});
|
|
42
42
|
abstract value: Primitives;
|
|
43
|
+
abstract reset(): any;
|
|
43
44
|
protected setupRuleNode(): void;
|
|
44
45
|
/**
|
|
45
46
|
* @private
|
|
@@ -54,6 +55,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
54
55
|
get index(): number;
|
|
55
56
|
get parent(): ContainerModel;
|
|
56
57
|
get type(): string | undefined;
|
|
58
|
+
get repeatable(): boolean;
|
|
57
59
|
get fieldType(): string;
|
|
58
60
|
get ':type'(): string;
|
|
59
61
|
get name(): string | undefined;
|
package/lib/BaseNode.js
CHANGED
|
@@ -20,6 +20,7 @@ exports.BaseNode = exports.exclude = exports.include = exports.dependencyTracked
|
|
|
20
20
|
const controller_1 = require("./controller");
|
|
21
21
|
const DataRefParser_1 = require("./utils/DataRefParser");
|
|
22
22
|
const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
|
|
23
|
+
const JsonUtils_1 = require("./utils/JsonUtils");
|
|
23
24
|
/**
|
|
24
25
|
* Defines the properties that are editable. These properties can be modified during rule execution.
|
|
25
26
|
*/
|
|
@@ -237,6 +238,9 @@ class BaseNode {
|
|
|
237
238
|
get type() {
|
|
238
239
|
return this._jsonModel.type;
|
|
239
240
|
}
|
|
241
|
+
get repeatable() {
|
|
242
|
+
return (0, JsonUtils_1.isRepeatable)(this._jsonModel);
|
|
243
|
+
}
|
|
240
244
|
get fieldType() {
|
|
241
245
|
return this._jsonModel.fieldType || 'text-input';
|
|
242
246
|
}
|
package/lib/Container.d.ts
CHANGED
|
@@ -35,112 +35,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
35
35
|
* Returns the current container state
|
|
36
36
|
*/
|
|
37
37
|
getState(): T & {
|
|
38
|
-
items:
|
|
39
|
-
id: string;
|
|
40
|
-
index: number;
|
|
41
|
-
':type': string;
|
|
42
|
-
description?: string | undefined;
|
|
43
|
-
rules?: import("./types").Items<string> | undefined;
|
|
44
|
-
events?: import("./types").Items<string | string[] | undefined> | undefined;
|
|
45
|
-
enumNames?: string[] | undefined;
|
|
46
|
-
enum?: any[] | undefined;
|
|
47
|
-
accept?: string[] | undefined;
|
|
48
|
-
enforceEnum?: boolean | undefined;
|
|
49
|
-
exclusiveMinimum?: number | undefined;
|
|
50
|
-
exclusiveMaximum?: number | undefined;
|
|
51
|
-
format?: string | undefined;
|
|
52
|
-
maxFileSize?: string | number | undefined;
|
|
53
|
-
maxLength?: number | undefined;
|
|
54
|
-
maximum?: number | undefined;
|
|
55
|
-
maxItems?: number | undefined;
|
|
56
|
-
minLength?: number | undefined;
|
|
57
|
-
minimum?: number | undefined;
|
|
58
|
-
minItems?: number | undefined;
|
|
59
|
-
pattern?: string | undefined;
|
|
60
|
-
required?: boolean | undefined;
|
|
61
|
-
/**
|
|
62
|
-
* @private
|
|
63
|
-
*/
|
|
64
|
-
step?: number | undefined;
|
|
65
|
-
type?: string | undefined;
|
|
66
|
-
validationExpression?: string | undefined;
|
|
67
|
-
uniqueItems?: boolean | undefined;
|
|
68
|
-
dataRef?: string | null | undefined;
|
|
69
|
-
label?: import("./types").Label | undefined;
|
|
70
|
-
enabled?: boolean | undefined;
|
|
71
|
-
visible?: boolean | undefined;
|
|
72
|
-
name?: string | undefined;
|
|
73
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
74
|
-
fieldType?: string | undefined; /**
|
|
75
|
-
* Returns the current container state
|
|
76
|
-
*/
|
|
77
|
-
errorMessage?: string | undefined;
|
|
78
|
-
properties?: {
|
|
79
|
-
[key: string]: any;
|
|
80
|
-
} | undefined;
|
|
81
|
-
screenReaderText?: string | undefined;
|
|
82
|
-
tooltip?: string | undefined;
|
|
83
|
-
altText?: string | undefined;
|
|
84
|
-
placeholder?: string | undefined;
|
|
85
|
-
readOnly?: boolean | undefined;
|
|
86
|
-
valid?: boolean | undefined;
|
|
87
|
-
default?: any;
|
|
88
|
-
value?: any;
|
|
89
|
-
displayFormat?: string | undefined;
|
|
90
|
-
editFormat?: string | undefined;
|
|
91
|
-
editValue?: string | undefined;
|
|
92
|
-
displayValue?: string | undefined;
|
|
93
|
-
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
94
|
-
} | {
|
|
95
|
-
id: string;
|
|
96
|
-
index: number;
|
|
97
|
-
':type': string;
|
|
98
|
-
description?: string | undefined;
|
|
99
|
-
rules?: import("./types").Items<string> | undefined;
|
|
100
|
-
events?: import("./types").Items<string | string[] | undefined> | undefined;
|
|
101
|
-
enumNames?: string[] | undefined;
|
|
102
|
-
enum?: any[] | undefined;
|
|
103
|
-
accept?: string[] | undefined;
|
|
104
|
-
enforceEnum?: boolean | undefined;
|
|
105
|
-
exclusiveMinimum?: number | undefined;
|
|
106
|
-
exclusiveMaximum?: number | undefined;
|
|
107
|
-
format?: string | undefined;
|
|
108
|
-
maxFileSize?: string | number | undefined;
|
|
109
|
-
maxLength?: number | undefined;
|
|
110
|
-
maximum?: number | undefined;
|
|
111
|
-
maxItems?: number | undefined;
|
|
112
|
-
minLength?: number | undefined;
|
|
113
|
-
minimum?: number | undefined;
|
|
114
|
-
minItems?: number | undefined;
|
|
115
|
-
pattern?: string | undefined;
|
|
116
|
-
required?: boolean | undefined;
|
|
117
|
-
/**
|
|
118
|
-
* @private
|
|
119
|
-
*/
|
|
120
|
-
step?: number | undefined;
|
|
121
|
-
type?: "object" | "array" | undefined;
|
|
122
|
-
validationExpression?: string | undefined;
|
|
123
|
-
uniqueItems?: boolean | undefined;
|
|
124
|
-
dataRef?: string | null | undefined;
|
|
125
|
-
label?: import("./types").Label | undefined;
|
|
126
|
-
enabled?: boolean | undefined;
|
|
127
|
-
visible?: boolean | undefined;
|
|
128
|
-
name?: string | undefined;
|
|
129
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
130
|
-
fieldType?: string | undefined; /**
|
|
131
|
-
* Returns the current container state
|
|
132
|
-
*/
|
|
133
|
-
errorMessage?: string | undefined;
|
|
134
|
-
properties?: {
|
|
135
|
-
[key: string]: any;
|
|
136
|
-
} | undefined;
|
|
137
|
-
screenReaderText?: string | undefined;
|
|
138
|
-
tooltip?: string | undefined;
|
|
139
|
-
altText?: string | undefined;
|
|
140
|
-
items: (FieldJson | ContainerJson)[] & import("./types").State<FieldJson | ContainerJson>[];
|
|
141
|
-
initialItems?: number | undefined;
|
|
142
|
-
activeChild?: string | undefined;
|
|
143
|
-
})[];
|
|
38
|
+
items: any[];
|
|
144
39
|
properties: {
|
|
145
40
|
[key: string]: any;
|
|
146
41
|
};
|
|
@@ -152,7 +47,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
152
47
|
':type': string;
|
|
153
48
|
id: string;
|
|
154
49
|
};
|
|
155
|
-
protected abstract _createChild(child: FieldsetJson | FieldJson): FieldModel | FieldsetModel;
|
|
50
|
+
protected abstract _createChild(child: FieldsetJson | FieldJson, options: any): FieldModel | FieldsetModel;
|
|
156
51
|
private _addChildToRuleNode;
|
|
157
52
|
private _addChild;
|
|
158
53
|
indexOf(f: FieldModel | FieldsetModel): number;
|
|
@@ -176,6 +71,12 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
176
71
|
* @private
|
|
177
72
|
*/
|
|
178
73
|
queueEvent(action: Action): void;
|
|
74
|
+
/**
|
|
75
|
+
* @summary reset the data of all the Fields present inside this container
|
|
76
|
+
* @method reset
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
reset(): void;
|
|
179
80
|
validate(): import("./types").ValidationError[];
|
|
180
81
|
/**
|
|
181
82
|
* @private
|
package/lib/Container.js
CHANGED
|
@@ -192,24 +192,24 @@ class Container extends Scriptable_1.default {
|
|
|
192
192
|
* @private
|
|
193
193
|
*/
|
|
194
194
|
addItem(action) {
|
|
195
|
-
if (action.type === 'addItem' && this._itemTemplate != null) {
|
|
195
|
+
if ((action.type === 'addItem' || action.type == 'addInstance') && this._itemTemplate != null) {
|
|
196
196
|
//@ts-ignore
|
|
197
197
|
if ((this._jsonModel.maxItems === -1) || (this._children.length < this._jsonModel.maxItems)) {
|
|
198
198
|
const dataNode = this.getDataNode();
|
|
199
|
-
let
|
|
200
|
-
if (typeof index !== 'number' || index > this._children.length) {
|
|
201
|
-
index = this._children.length;
|
|
202
|
-
}
|
|
199
|
+
let instanceIndex = action.payload;
|
|
203
200
|
const retVal = this._addChild(this._itemTemplate, action.payload, true);
|
|
204
|
-
|
|
201
|
+
if (typeof instanceIndex !== 'number' || instanceIndex > this._children.length) {
|
|
202
|
+
instanceIndex = this._children.length;
|
|
203
|
+
}
|
|
204
|
+
const _data = retVal.defaultDataModel(instanceIndex);
|
|
205
205
|
if (_data) {
|
|
206
|
-
dataNode.$addDataNode(
|
|
206
|
+
dataNode.$addDataNode(instanceIndex, _data);
|
|
207
207
|
}
|
|
208
208
|
retVal._initialize();
|
|
209
209
|
this.notifyDependents((0, controller_1.propertyChange)('items', retVal.getState(), null));
|
|
210
210
|
retVal.dispatch(new controller_1.Initialize());
|
|
211
211
|
retVal.dispatch(new controller_1.ExecuteRule());
|
|
212
|
-
for (let i =
|
|
212
|
+
for (let i = instanceIndex + 1; i < this._children.length; i++) {
|
|
213
213
|
this._children[i].dispatch(new controller_1.ExecuteRule());
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -219,21 +219,24 @@ class Container extends Scriptable_1.default {
|
|
|
219
219
|
* @private
|
|
220
220
|
*/
|
|
221
221
|
removeItem(action) {
|
|
222
|
-
if (action.type === 'removeItem' && this._itemTemplate != null) {
|
|
222
|
+
if ((action.type === 'removeItem' || action.type == 'removeInstance') && this._itemTemplate != null) {
|
|
223
223
|
if (this._children.length == 0) {
|
|
224
224
|
//can't remove item if there isn't any
|
|
225
225
|
return;
|
|
226
226
|
}
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
let instanceIndex = action.payload;
|
|
228
|
+
if (typeof instanceIndex !== 'number') {
|
|
229
|
+
instanceIndex = this._children.length - 1;
|
|
230
|
+
}
|
|
231
|
+
const state = this._children[instanceIndex].getState();
|
|
229
232
|
//@ts-ignore
|
|
230
233
|
if (this._children.length > this._jsonModel.minItems) {
|
|
231
234
|
// clear child
|
|
232
235
|
//remove field
|
|
233
236
|
this._childrenReference.pop();
|
|
234
|
-
this._children.splice(
|
|
235
|
-
this.getDataNode().$removeDataNode(
|
|
236
|
-
for (let i =
|
|
237
|
+
this._children.splice(instanceIndex, 1);
|
|
238
|
+
this.getDataNode().$removeDataNode(instanceIndex);
|
|
239
|
+
for (let i = instanceIndex; i < this._children.length; i++) {
|
|
237
240
|
this._children[i].dispatch(new controller_1.ExecuteRule());
|
|
238
241
|
}
|
|
239
242
|
this.notifyDependents((0, controller_1.propertyChange)('items', null, state));
|
|
@@ -253,6 +256,17 @@ class Container extends Scriptable_1.default {
|
|
|
253
256
|
});
|
|
254
257
|
}
|
|
255
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* @summary reset the data of all the Fields present inside this container
|
|
261
|
+
* @method reset
|
|
262
|
+
* @private
|
|
263
|
+
*/
|
|
264
|
+
reset() {
|
|
265
|
+
this.items.forEach(x => {
|
|
266
|
+
//@ts-ignore
|
|
267
|
+
x.reset();
|
|
268
|
+
});
|
|
269
|
+
}
|
|
256
270
|
validate() {
|
|
257
271
|
return this.items.flatMap(x => {
|
|
258
272
|
return x.validate();
|
package/lib/Field.d.ts
CHANGED
|
@@ -59,8 +59,15 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
59
59
|
get editValue(): any;
|
|
60
60
|
get displayValue(): any;
|
|
61
61
|
protected getDataNodeValue(typedValue: any): any;
|
|
62
|
+
private updateDataNodeAndTypedValue;
|
|
62
63
|
get value(): any;
|
|
63
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;
|
|
64
71
|
protected _updateRuleNodeReference(value: any): void;
|
|
65
72
|
protected getInternalType(): string | undefined;
|
|
66
73
|
valueOf(): any;
|
|
@@ -187,6 +194,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
187
194
|
get exclusiveMaximum(): number | undefined;
|
|
188
195
|
set exclusiveMaximum(eM: number | undefined);
|
|
189
196
|
get default(): any;
|
|
197
|
+
private isNotEmpty;
|
|
190
198
|
/**
|
|
191
199
|
* @private
|
|
192
200
|
*/
|
|
@@ -219,6 +227,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
219
227
|
maxLength?: number | undefined;
|
|
220
228
|
maximum?: number | undefined;
|
|
221
229
|
maxItems?: number | undefined;
|
|
230
|
+
minOccur?: number | undefined;
|
|
231
|
+
maxOccur?: number | undefined;
|
|
222
232
|
minLength?: number | undefined;
|
|
223
233
|
minimum?: number | undefined;
|
|
224
234
|
minItems?: number | undefined;
|
|
@@ -240,6 +250,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
240
250
|
properties: {
|
|
241
251
|
[key: string]: any;
|
|
242
252
|
};
|
|
253
|
+
repeatable?: boolean | undefined;
|
|
243
254
|
screenReaderText?: string | undefined;
|
|
244
255
|
tooltip?: string | undefined;
|
|
245
256
|
altText?: string | undefined;
|
package/lib/Field.js
CHANGED
|
@@ -269,7 +269,7 @@ class Field extends Scriptable_1.default {
|
|
|
269
269
|
}
|
|
270
270
|
get editValue() {
|
|
271
271
|
const format = this.editFormat;
|
|
272
|
-
if (this.format == 'date' && this.value
|
|
272
|
+
if (this.format == 'date' && this.isNotEmpty(this.value) && this.valid !== false) {
|
|
273
273
|
return (0, af_formatters_1.formatDate)(new Date(this.value), this.language, format);
|
|
274
274
|
}
|
|
275
275
|
else {
|
|
@@ -278,7 +278,7 @@ class Field extends Scriptable_1.default {
|
|
|
278
278
|
}
|
|
279
279
|
get displayValue() {
|
|
280
280
|
const format = this.displayFormat;
|
|
281
|
-
if (this.format == 'date' && this.value
|
|
281
|
+
if (this.format == 'date' && this.isNotEmpty(this.value) && this.valid !== false) {
|
|
282
282
|
return (0, af_formatters_1.formatDate)(new Date(this.value), this.language, format);
|
|
283
283
|
}
|
|
284
284
|
else {
|
|
@@ -288,34 +288,41 @@ class Field extends Scriptable_1.default {
|
|
|
288
288
|
getDataNodeValue(typedValue) {
|
|
289
289
|
return this.isEmpty() ? this.emptyValue : typedValue;
|
|
290
290
|
}
|
|
291
|
-
|
|
292
|
-
if (this._jsonModel.value === undefined) {
|
|
293
|
-
return null;
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
return this._jsonModel.value;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
set value(v) {
|
|
291
|
+
updateDataNodeAndTypedValue(val) {
|
|
300
292
|
const dataNode = this.getDataNode();
|
|
301
293
|
if (BaseNode_1.staticFields.indexOf(this.fieldType) > -1 && typeof dataNode !== 'undefined') {
|
|
302
294
|
// if a static field is bound to data node it can not be updated.
|
|
303
295
|
return;
|
|
304
296
|
}
|
|
305
297
|
const Constraints = this._getConstraintObject();
|
|
306
|
-
const typeRes = Constraints.type(this.getInternalType() || 'string',
|
|
298
|
+
const typeRes = Constraints.type(this.getInternalType() || 'string', val);
|
|
307
299
|
const changes = this._setProperty('value', typeRes.value, false);
|
|
308
|
-
let uniqueRes = { valid: true };
|
|
309
300
|
if (changes.length > 0) {
|
|
310
301
|
this._updateRuleNodeReference(typeRes.value);
|
|
311
302
|
if (typeof dataNode !== 'undefined') {
|
|
312
303
|
dataNode.setValue(this.getDataNodeValue(this._jsonModel.value), this._jsonModel.value, this);
|
|
313
304
|
}
|
|
305
|
+
}
|
|
306
|
+
return changes;
|
|
307
|
+
}
|
|
308
|
+
get value() {
|
|
309
|
+
if (this._jsonModel.value === undefined) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
return this._jsonModel.value;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
set value(v) {
|
|
317
|
+
const changes = this.updateDataNodeAndTypedValue(v);
|
|
318
|
+
let uniqueRes = { valid: true };
|
|
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);
|
|
314
322
|
if (this.parent.uniqueItems && this.parent.type === 'array') {
|
|
315
323
|
// @ts-ignore
|
|
316
|
-
uniqueRes = Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
|
|
324
|
+
uniqueRes = ValidationUtils_1.Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
|
|
317
325
|
}
|
|
318
|
-
let updates;
|
|
319
326
|
if (typeRes.valid && uniqueRes.valid) {
|
|
320
327
|
updates = this.evaluateConstraints();
|
|
321
328
|
}
|
|
@@ -333,6 +340,28 @@ class Field extends Scriptable_1.default {
|
|
|
333
340
|
this.dispatch(changeAction);
|
|
334
341
|
}
|
|
335
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
|
+
}
|
|
336
365
|
_updateRuleNodeReference(value) {
|
|
337
366
|
var _a;
|
|
338
367
|
if ((_a = this.type) === null || _a === void 0 ? void 0 : _a.endsWith('[]')) {
|
|
@@ -528,6 +557,9 @@ class Field extends Scriptable_1.default {
|
|
|
528
557
|
get default() {
|
|
529
558
|
return this._jsonModel.default;
|
|
530
559
|
}
|
|
560
|
+
isNotEmpty(value) {
|
|
561
|
+
return value != null && value !== '';
|
|
562
|
+
}
|
|
531
563
|
/**
|
|
532
564
|
* @private
|
|
533
565
|
*/
|
|
@@ -543,7 +575,7 @@ class Field extends Scriptable_1.default {
|
|
|
543
575
|
(this.isArrayType() && this.required ? value.length > 0 : true);
|
|
544
576
|
constraint = 'required';
|
|
545
577
|
}
|
|
546
|
-
if (valid &&
|
|
578
|
+
if (valid && this.isNotEmpty(value)) {
|
|
547
579
|
const invalidConstraint = supportedConstraints.find(key => {
|
|
548
580
|
// @ts-ignore
|
|
549
581
|
if (key in elem && elem[key] !== undefined) {
|
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/Form.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Container from './Container';
|
|
2
|
-
import { Action, BaseModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormJson, FormModel
|
|
2
|
+
import { Action, BaseModel, FieldJson, FieldModel, FieldsetJson, FieldsetModel, FormJson, FormModel } from './types';
|
|
3
3
|
import FormMetaData from './FormMetaData';
|
|
4
4
|
import EventQueue from './controller/EventQueue';
|
|
5
5
|
import { Logger, LogLevel } from './controller/Logger';
|
|
@@ -63,7 +63,11 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
63
63
|
maxFileSize?: string | number | undefined;
|
|
64
64
|
maxLength?: number | undefined;
|
|
65
65
|
maximum?: number | undefined;
|
|
66
|
-
maxItems?: number | undefined;
|
|
66
|
+
maxItems?: number | undefined; /**
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
minOccur?: number | undefined;
|
|
70
|
+
maxOccur?: number | undefined;
|
|
67
71
|
minLength?: number | undefined;
|
|
68
72
|
minimum?: number | undefined;
|
|
69
73
|
minItems?: number | undefined;
|
|
@@ -86,6 +90,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
86
90
|
properties?: {
|
|
87
91
|
[key: string]: any;
|
|
88
92
|
} | undefined;
|
|
93
|
+
repeatable?: boolean | undefined;
|
|
89
94
|
screenReaderText?: string | undefined;
|
|
90
95
|
tooltip?: string | undefined;
|
|
91
96
|
altText?: string | undefined;
|
|
@@ -98,113 +103,12 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
98
103
|
data?: any;
|
|
99
104
|
title?: string | undefined;
|
|
100
105
|
action?: string | undefined;
|
|
101
|
-
adaptiveForm?: string | undefined;
|
|
106
|
+
adaptiveForm?: string | undefined; /**
|
|
107
|
+
* @param field
|
|
108
|
+
* @private
|
|
109
|
+
*/
|
|
102
110
|
} & {
|
|
103
|
-
items:
|
|
104
|
-
id: string;
|
|
105
|
-
index: number;
|
|
106
|
-
':type': string;
|
|
107
|
-
description?: string | undefined;
|
|
108
|
-
rules?: Items<string> | undefined;
|
|
109
|
-
events?: Items<string | string[] | undefined> | undefined;
|
|
110
|
-
enumNames?: string[] | undefined;
|
|
111
|
-
enum?: any[] | undefined;
|
|
112
|
-
accept?: string[] | undefined;
|
|
113
|
-
enforceEnum?: boolean | undefined;
|
|
114
|
-
exclusiveMinimum?: number | undefined;
|
|
115
|
-
exclusiveMaximum?: number | undefined;
|
|
116
|
-
format?: string | undefined;
|
|
117
|
-
maxFileSize?: string | number | undefined;
|
|
118
|
-
maxLength?: number | undefined;
|
|
119
|
-
maximum?: number | undefined;
|
|
120
|
-
maxItems?: number | undefined;
|
|
121
|
-
minLength?: number | undefined;
|
|
122
|
-
minimum?: number | undefined;
|
|
123
|
-
minItems?: number | undefined;
|
|
124
|
-
pattern?: string | undefined;
|
|
125
|
-
required?: boolean | undefined;
|
|
126
|
-
step?: number | undefined;
|
|
127
|
-
type?: string | undefined;
|
|
128
|
-
validationExpression?: string | undefined;
|
|
129
|
-
uniqueItems?: boolean | undefined;
|
|
130
|
-
dataRef?: string | null | undefined;
|
|
131
|
-
label?: import("./types").Label | undefined;
|
|
132
|
-
enabled?: boolean | undefined;
|
|
133
|
-
visible?: boolean | undefined;
|
|
134
|
-
name?: string | undefined;
|
|
135
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
136
|
-
fieldType?: string | undefined;
|
|
137
|
-
errorMessage?: string | undefined;
|
|
138
|
-
properties?: {
|
|
139
|
-
[key: string]: any;
|
|
140
|
-
} | undefined;
|
|
141
|
-
screenReaderText?: string | undefined;
|
|
142
|
-
tooltip?: string | undefined;
|
|
143
|
-
altText?: string | undefined;
|
|
144
|
-
placeholder?: string | undefined; /**
|
|
145
|
-
* Returns the current state of the form
|
|
146
|
-
*
|
|
147
|
-
* To access the form data and attachments, one needs to use the `data` and `attachments` property.
|
|
148
|
-
* For example,
|
|
149
|
-
* ```
|
|
150
|
-
* const data = form.getState().data
|
|
151
|
-
* const attachments = form.getState().attachments
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
readOnly?: boolean | undefined;
|
|
155
|
-
valid?: boolean | undefined;
|
|
156
|
-
default?: any;
|
|
157
|
-
value?: any;
|
|
158
|
-
displayFormat?: string | undefined;
|
|
159
|
-
editFormat?: string | undefined;
|
|
160
|
-
editValue?: string | undefined;
|
|
161
|
-
displayValue?: string | undefined;
|
|
162
|
-
emptyValue?: "" | "undefined" | "null" | undefined;
|
|
163
|
-
} | {
|
|
164
|
-
id: string;
|
|
165
|
-
index: number;
|
|
166
|
-
':type': string;
|
|
167
|
-
description?: string | undefined;
|
|
168
|
-
rules?: Items<string> | undefined;
|
|
169
|
-
events?: Items<string | string[] | undefined> | undefined;
|
|
170
|
-
enumNames?: string[] | undefined;
|
|
171
|
-
enum?: any[] | undefined;
|
|
172
|
-
accept?: string[] | undefined;
|
|
173
|
-
enforceEnum?: boolean | undefined;
|
|
174
|
-
exclusiveMinimum?: number | undefined;
|
|
175
|
-
exclusiveMaximum?: number | undefined;
|
|
176
|
-
format?: string | undefined;
|
|
177
|
-
maxFileSize?: string | number | undefined;
|
|
178
|
-
maxLength?: number | undefined;
|
|
179
|
-
maximum?: number | undefined;
|
|
180
|
-
maxItems?: number | undefined;
|
|
181
|
-
minLength?: number | undefined;
|
|
182
|
-
minimum?: number | undefined;
|
|
183
|
-
minItems?: number | undefined;
|
|
184
|
-
pattern?: string | undefined;
|
|
185
|
-
required?: boolean | undefined;
|
|
186
|
-
step?: number | undefined;
|
|
187
|
-
type?: "object" | "array" | undefined;
|
|
188
|
-
validationExpression?: string | undefined;
|
|
189
|
-
uniqueItems?: boolean | undefined;
|
|
190
|
-
dataRef?: string | null | undefined;
|
|
191
|
-
label?: import("./types").Label | undefined;
|
|
192
|
-
enabled?: boolean | undefined;
|
|
193
|
-
visible?: boolean | undefined;
|
|
194
|
-
name?: string | undefined;
|
|
195
|
-
constraintMessages?: import("./types").ConstraintsMessages | undefined;
|
|
196
|
-
fieldType?: string | undefined;
|
|
197
|
-
errorMessage?: string | undefined;
|
|
198
|
-
properties?: {
|
|
199
|
-
[key: string]: any;
|
|
200
|
-
} | undefined;
|
|
201
|
-
screenReaderText?: string | undefined;
|
|
202
|
-
tooltip?: string | undefined;
|
|
203
|
-
altText?: string | undefined;
|
|
204
|
-
items: (FieldJson | import("./types").ContainerJson)[] & import("./types").State<FieldJson | import("./types").ContainerJson>[];
|
|
205
|
-
initialItems?: number | undefined;
|
|
206
|
-
activeChild?: string | undefined;
|
|
207
|
-
})[];
|
|
111
|
+
items: any[];
|
|
208
112
|
properties: {
|
|
209
113
|
[key: string]: any;
|
|
210
114
|
};
|
|
@@ -226,6 +130,19 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
226
130
|
* @private
|
|
227
131
|
*/
|
|
228
132
|
fieldAdded(field: FieldModel | FieldsetModel): void;
|
|
133
|
+
/**
|
|
134
|
+
* visits each element in the form
|
|
135
|
+
* @param callBack a function which is invoked on each form element
|
|
136
|
+
* (including container type elements) visited
|
|
137
|
+
*/
|
|
138
|
+
visit(callBack: (field: FieldModel | FieldsetModel) => void): void;
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
* @param container
|
|
142
|
+
* @param callBack
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
traverseChild(container: Container<any>, callBack: (field: FieldModel | FieldsetModel) => void): void;
|
|
229
146
|
validate(): import("./types").ValidationError[];
|
|
230
147
|
/**
|
|
231
148
|
* Checks if the given form is valid or not
|