@aemforms/af-core 0.21.0 → 0.22.4
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 +1 -0
- package/lib/BaseNode.js +7 -0
- package/lib/Container.d.ts +6 -0
- package/lib/Container.js +1 -7
- package/lib/Field.d.ts +3 -7
- package/lib/Field.js +14 -4
- package/lib/Fieldset.d.ts +3 -0
- package/lib/Fieldset.js +12 -0
- package/lib/FileUpload.d.ts +5 -0
- package/lib/FileUpload.js +30 -3
- package/lib/Form.d.ts +28 -0
- package/lib/Form.js +1 -0
- package/lib/FormInstance.d.ts +12 -0
- package/lib/FormInstance.js +26 -1
- package/lib/controller/Controller.d.ts +9 -0
- package/lib/controller/Controller.js +13 -1
- package/lib/rules/FunctionRuntime.d.ts +8 -0
- package/lib/rules/FunctionRuntime.js +18 -0
- package/lib/types/Json.d.ts +1 -0
- package/lib/types/Json.js +4 -1
- package/lib/utils/TranslationUtils.d.ts +1 -1
- package/lib/utils/TranslationUtils.js +10 -2
- package/package.json +1 -1
package/lib/BaseNode.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
|
|
|
53
53
|
get ruleEngine(): import("./rules/RuleEngine").default;
|
|
54
54
|
get label(): import("./types").Label | undefined;
|
|
55
55
|
set label(l: import("./types").Label | undefined);
|
|
56
|
+
get uniqueItems(): boolean | undefined;
|
|
56
57
|
/**
|
|
57
58
|
* Transparent form fields are meant only for creation of view. They are also not part of data
|
|
58
59
|
*/
|
package/lib/BaseNode.js
CHANGED
|
@@ -109,6 +109,10 @@ class BaseNode {
|
|
|
109
109
|
//look for property
|
|
110
110
|
if (prop.startsWith('$')) {
|
|
111
111
|
prop = prop.substr(1);
|
|
112
|
+
if (prop === 'parent') {
|
|
113
|
+
return this[prop].getRuleNode();
|
|
114
|
+
}
|
|
115
|
+
//@ts-ignore
|
|
112
116
|
//@todo: create a list of properties that are allowed
|
|
113
117
|
//@ts-ignore
|
|
114
118
|
// return only non functional properties in this object
|
|
@@ -185,6 +189,9 @@ class BaseNode {
|
|
|
185
189
|
this.notifyDependents(changeAction);
|
|
186
190
|
}
|
|
187
191
|
}
|
|
192
|
+
get uniqueItems() {
|
|
193
|
+
return this._jsonModel.uniqueItems;
|
|
194
|
+
}
|
|
188
195
|
/**
|
|
189
196
|
* Transparent form fields are meant only for creation of view. They are also not part of data
|
|
190
197
|
*/
|
package/lib/Container.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
56
56
|
step?: number | undefined;
|
|
57
57
|
type?: string | undefined;
|
|
58
58
|
validationExpression?: string | undefined;
|
|
59
|
+
uniqueItems?: boolean | undefined;
|
|
59
60
|
dataRef?: string | null | undefined;
|
|
60
61
|
':type': string;
|
|
61
62
|
label?: import("./types").Label | undefined;
|
|
@@ -98,6 +99,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
98
99
|
step?: number | undefined;
|
|
99
100
|
type?: "object" | "array" | undefined;
|
|
100
101
|
validationExpression?: string | undefined;
|
|
102
|
+
uniqueItems?: boolean | undefined;
|
|
101
103
|
dataRef?: string | null | undefined;
|
|
102
104
|
':type'?: string | undefined;
|
|
103
105
|
label?: import("./types").Label | undefined;
|
|
@@ -133,6 +135,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
133
135
|
step?: number | undefined;
|
|
134
136
|
type?: string | undefined;
|
|
135
137
|
validationExpression?: string | undefined;
|
|
138
|
+
uniqueItems?: boolean | undefined;
|
|
136
139
|
} & {
|
|
137
140
|
dataRef?: string | null | undefined;
|
|
138
141
|
':type'?: string | undefined;
|
|
@@ -180,6 +183,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
180
183
|
step?: number | undefined;
|
|
181
184
|
type?: string | undefined;
|
|
182
185
|
validationExpression?: string | undefined;
|
|
186
|
+
uniqueItems?: boolean | undefined;
|
|
183
187
|
} & {
|
|
184
188
|
dataRef?: string | null | undefined;
|
|
185
189
|
':type'?: string | undefined;
|
|
@@ -221,6 +225,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
221
225
|
step?: number | undefined;
|
|
222
226
|
type?: string | undefined;
|
|
223
227
|
validationExpression?: string | undefined;
|
|
228
|
+
uniqueItems?: boolean | undefined;
|
|
224
229
|
} & {
|
|
225
230
|
dataRef?: string | null | undefined;
|
|
226
231
|
':type'?: string | undefined;
|
|
@@ -268,6 +273,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
|
|
|
268
273
|
step?: number | undefined;
|
|
269
274
|
type?: string | undefined;
|
|
270
275
|
validationExpression?: string | undefined;
|
|
276
|
+
uniqueItems?: boolean | undefined;
|
|
271
277
|
} & {
|
|
272
278
|
dataRef?: string | null | undefined;
|
|
273
279
|
':type'?: string | undefined;
|
package/lib/Container.js
CHANGED
|
@@ -199,7 +199,7 @@ class Container extends Scriptable_1.default {
|
|
|
199
199
|
*/
|
|
200
200
|
removeItem(action) {
|
|
201
201
|
if (action.type === 'removeItem' && this._itemTemplate != null) {
|
|
202
|
-
const index = action.payload
|
|
202
|
+
const index = typeof action.payload === 'number' ? action.payload : this._children.length - 1;
|
|
203
203
|
const state = this._children[index].getState();
|
|
204
204
|
//@ts-ignore
|
|
205
205
|
if (this._children.length > this._jsonModel.minItems) {
|
|
@@ -237,13 +237,7 @@ class Container extends Scriptable_1.default {
|
|
|
237
237
|
* @private
|
|
238
238
|
*/
|
|
239
239
|
dispatch(action) {
|
|
240
|
-
var _a;
|
|
241
240
|
super.dispatch(action);
|
|
242
|
-
if ((_a = action.metadata) === null || _a === void 0 ? void 0 : _a.dispatch) {
|
|
243
|
-
this.items.forEach(x => {
|
|
244
|
-
x.dispatch(action);
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
241
|
}
|
|
248
242
|
/**
|
|
249
243
|
* @private
|
package/lib/Field.d.ts
CHANGED
|
@@ -79,12 +79,6 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
79
79
|
valid: boolean;
|
|
80
80
|
value: number;
|
|
81
81
|
};
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
* @param value
|
|
85
|
-
* @param constraints
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
82
|
maximum: (constraint: number, value: number) => {
|
|
89
83
|
valid: boolean;
|
|
90
84
|
value: number;
|
|
@@ -110,7 +104,9 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
|
|
|
110
104
|
value: T_2[];
|
|
111
105
|
};
|
|
112
106
|
minLength: (constraint: number, value: string) => {
|
|
113
|
-
value: string;
|
|
107
|
+
value: string; /**
|
|
108
|
+
* returns the format constraint
|
|
109
|
+
*/
|
|
114
110
|
valid: boolean;
|
|
115
111
|
};
|
|
116
112
|
maxLength: (constraint: number, value: string) => {
|
package/lib/Field.js
CHANGED
|
@@ -176,19 +176,24 @@ class Field extends Scriptable_1.default {
|
|
|
176
176
|
const Constraints = this._getConstraintObject();
|
|
177
177
|
const typeRes = Constraints.type(this._jsonModel.type || 'string', v);
|
|
178
178
|
const changes = this._setProperty('value', typeRes.value, false);
|
|
179
|
+
let uniqueRes = { valid: true };
|
|
179
180
|
if (changes.length > 0) {
|
|
180
181
|
const dataNode = this.getDataNode();
|
|
181
182
|
if (typeof dataNode !== 'undefined') {
|
|
182
183
|
dataNode.setValue(this.isEmpty() ? this.emptyValue : this._jsonModel.value, this._jsonModel.value);
|
|
183
184
|
}
|
|
185
|
+
if (this.parent.uniqueItems && this.parent.type === 'array') {
|
|
186
|
+
// @ts-ignore
|
|
187
|
+
uniqueRes = Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
|
|
188
|
+
}
|
|
184
189
|
let updates;
|
|
185
|
-
if (typeRes.valid) {
|
|
190
|
+
if (typeRes.valid && uniqueRes.valid) {
|
|
186
191
|
updates = this.evaluateConstraints();
|
|
187
192
|
}
|
|
188
193
|
else {
|
|
189
194
|
const changes = {
|
|
190
|
-
'valid': typeRes.valid,
|
|
191
|
-
'errorMessage': typeRes.valid ? '' : this.getErrorMessage('type')
|
|
195
|
+
'valid': typeRes.valid && uniqueRes.valid,
|
|
196
|
+
'errorMessage': typeRes.valid && uniqueRes.valid ? '' : this.getErrorMessage('type')
|
|
192
197
|
};
|
|
193
198
|
updates = this._applyUpdates(['valid', 'errorMessage'], changes);
|
|
194
199
|
}
|
|
@@ -332,7 +337,12 @@ class Field extends Scriptable_1.default {
|
|
|
332
337
|
// @ts-ignore
|
|
333
338
|
const fn = Constraints[key];
|
|
334
339
|
if (value instanceof Array && this.isArrayType()) {
|
|
335
|
-
|
|
340
|
+
if (ValidationUtils_1.ValidConstraints.array.indexOf(key) !== -1) {
|
|
341
|
+
return !fn(restriction, value).valid;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
return value.some(x => !(fn(restriction, x).valid));
|
|
345
|
+
}
|
|
336
346
|
}
|
|
337
347
|
else if (typeof fn === 'function') {
|
|
338
348
|
return !fn(restriction, value).valid;
|
package/lib/Fieldset.d.ts
CHANGED
|
@@ -28,4 +28,7 @@ export declare class Fieldset extends Container<FieldsetJson> implements Fieldse
|
|
|
28
28
|
protected _createChild(child: FieldsetJson | FieldJson, options: any): FieldModel | FieldsetModel;
|
|
29
29
|
get items(): (FieldModel | FieldsetModel)[];
|
|
30
30
|
get value(): null;
|
|
31
|
+
get fieldType(): string;
|
|
32
|
+
get enabled(): boolean | undefined;
|
|
33
|
+
set enabled(e: boolean | undefined);
|
|
31
34
|
}
|
package/lib/Fieldset.js
CHANGED
|
@@ -74,6 +74,9 @@ class Fieldset extends Container_1.default {
|
|
|
74
74
|
this._jsonModel[key] = value;
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
|
+
if (this._jsonModel.dataRef && this._jsonModel.type === undefined) {
|
|
78
|
+
this._jsonModel.type = 'object';
|
|
79
|
+
}
|
|
77
80
|
}
|
|
78
81
|
get type() {
|
|
79
82
|
const ret = super.type;
|
|
@@ -93,5 +96,14 @@ class Fieldset extends Container_1.default {
|
|
|
93
96
|
get value() {
|
|
94
97
|
return null;
|
|
95
98
|
}
|
|
99
|
+
get fieldType() {
|
|
100
|
+
return 'panel';
|
|
101
|
+
}
|
|
102
|
+
get enabled() {
|
|
103
|
+
return this._jsonModel.enabled;
|
|
104
|
+
}
|
|
105
|
+
set enabled(e) {
|
|
106
|
+
this._setProperty('enabled', e);
|
|
107
|
+
}
|
|
96
108
|
}
|
|
97
109
|
exports.Fieldset = Fieldset;
|
package/lib/FileUpload.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ declare class FileUpload extends Field implements FieldModel {
|
|
|
33
33
|
valid: boolean;
|
|
34
34
|
value: any;
|
|
35
35
|
};
|
|
36
|
+
checkFileType(type: any): boolean;
|
|
37
|
+
acceptCheck(value: any): {
|
|
38
|
+
valid: boolean;
|
|
39
|
+
value: any;
|
|
40
|
+
};
|
|
36
41
|
get value(): any;
|
|
37
42
|
set value(value: any);
|
|
38
43
|
private _serialize;
|
package/lib/FileUpload.js
CHANGED
|
@@ -177,6 +177,32 @@ class FileUpload extends Field_1.default {
|
|
|
177
177
|
return ValidationUtils_1.Constraints.type(type, value);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
+
checkFileType(type) {
|
|
181
|
+
let accepts = this.accept || '';
|
|
182
|
+
let validFileType = false;
|
|
183
|
+
if (!accepts || !type) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
accepts = Array.isArray(accepts) ? accepts : accepts.split(',');
|
|
187
|
+
accepts.forEach((accept) => {
|
|
188
|
+
const prefixAccept = accept.split('/')[0];
|
|
189
|
+
const suffixAccept = accept.split('.')[1];
|
|
190
|
+
if ((accept.includes('*') && type.startsWith(prefixAccept)) ||
|
|
191
|
+
(accept.includes('.') && type.endsWith(suffixAccept)) ||
|
|
192
|
+
(accept === type)) {
|
|
193
|
+
validFileType = true;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return validFileType;
|
|
197
|
+
}
|
|
198
|
+
acceptCheck(value) {
|
|
199
|
+
const tempValue = value instanceof Array ? value : [value];
|
|
200
|
+
const invalidFile = tempValue.some((file) => !this.checkFileType(file.type || file.mediaType));
|
|
201
|
+
return {
|
|
202
|
+
valid: !invalidFile,
|
|
203
|
+
value
|
|
204
|
+
};
|
|
205
|
+
}
|
|
180
206
|
get value() {
|
|
181
207
|
// @ts-ignore
|
|
182
208
|
this.ruleEngine.trackDependency(this);
|
|
@@ -219,6 +245,7 @@ class FileUpload extends Field_1.default {
|
|
|
219
245
|
if (value !== undefined) {
|
|
220
246
|
// store file list here
|
|
221
247
|
const typeRes = this.typeCheck(value);
|
|
248
|
+
const acceptRes = this.acceptCheck(value);
|
|
222
249
|
const changes = this._setProperty('value', typeRes.value, false);
|
|
223
250
|
let fileInfoPayload = FileUpload.extractFileInfo(value);
|
|
224
251
|
fileInfoPayload = this.coerce(fileInfoPayload);
|
|
@@ -242,13 +269,13 @@ class FileUpload extends Field_1.default {
|
|
|
242
269
|
}
|
|
243
270
|
}
|
|
244
271
|
let updates;
|
|
245
|
-
if (typeRes.valid) {
|
|
272
|
+
if (typeRes.valid && acceptRes.valid) {
|
|
246
273
|
updates = this.evaluateConstraints();
|
|
247
274
|
}
|
|
248
275
|
else {
|
|
249
276
|
const changes = {
|
|
250
|
-
'valid': typeRes.valid,
|
|
251
|
-
'errorMessage': typeRes.valid ? '' : this.getErrorMessage('type')
|
|
277
|
+
'valid': typeRes.valid && acceptRes.valid,
|
|
278
|
+
'errorMessage': typeRes.valid && acceptRes.valid ? '' : this.getErrorMessage('type')
|
|
252
279
|
};
|
|
253
280
|
updates = this._applyUpdates(['valid', 'errorMessage'], changes);
|
|
254
281
|
}
|
package/lib/Form.d.ts
CHANGED
|
@@ -70,6 +70,9 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
70
70
|
enum?: any[] | undefined;
|
|
71
71
|
} & {
|
|
72
72
|
accept?: string[] | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
73
76
|
enforceEnum?: boolean | undefined;
|
|
74
77
|
exclusiveMinimum?: number | undefined;
|
|
75
78
|
exclusiveMaximum?: number | undefined;
|
|
@@ -86,6 +89,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
86
89
|
step?: number | undefined;
|
|
87
90
|
type?: string | undefined;
|
|
88
91
|
validationExpression?: string | undefined;
|
|
92
|
+
uniqueItems?: boolean | undefined;
|
|
89
93
|
} & {
|
|
90
94
|
dataRef?: string | null | undefined;
|
|
91
95
|
':type'?: string | undefined;
|
|
@@ -117,6 +121,9 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
117
121
|
enumNames?: string[] | undefined;
|
|
118
122
|
enum?: any[] | undefined;
|
|
119
123
|
accept?: string[] | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
120
127
|
enforceEnum?: boolean | undefined;
|
|
121
128
|
exclusiveMinimum?: number | undefined;
|
|
122
129
|
exclusiveMaximum?: number | undefined;
|
|
@@ -133,6 +140,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
133
140
|
step?: number | undefined;
|
|
134
141
|
type?: string | undefined;
|
|
135
142
|
validationExpression?: string | undefined;
|
|
143
|
+
uniqueItems?: boolean | undefined;
|
|
136
144
|
dataRef?: string | null | undefined;
|
|
137
145
|
':type': string;
|
|
138
146
|
label?: import("./types").Label | undefined;
|
|
@@ -159,6 +167,9 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
159
167
|
enumNames?: string[] | undefined;
|
|
160
168
|
enum?: any[] | undefined;
|
|
161
169
|
accept?: string[] | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* @private
|
|
172
|
+
*/
|
|
162
173
|
enforceEnum?: boolean | undefined;
|
|
163
174
|
exclusiveMinimum?: number | undefined;
|
|
164
175
|
exclusiveMaximum?: number | undefined;
|
|
@@ -175,6 +186,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
175
186
|
step?: number | undefined;
|
|
176
187
|
type?: "object" | "array" | undefined;
|
|
177
188
|
validationExpression?: string | undefined;
|
|
189
|
+
uniqueItems?: boolean | undefined;
|
|
178
190
|
dataRef?: string | null | undefined;
|
|
179
191
|
':type'?: string | undefined;
|
|
180
192
|
label?: import("./types").Label | undefined;
|
|
@@ -194,6 +206,9 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
194
206
|
enum?: any[] | undefined;
|
|
195
207
|
} & {
|
|
196
208
|
accept?: string[] | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* @private
|
|
211
|
+
*/
|
|
197
212
|
enforceEnum?: boolean | undefined;
|
|
198
213
|
exclusiveMinimum?: number | undefined;
|
|
199
214
|
exclusiveMaximum?: number | undefined;
|
|
@@ -210,6 +225,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
210
225
|
step?: number | undefined;
|
|
211
226
|
type?: string | undefined;
|
|
212
227
|
validationExpression?: string | undefined;
|
|
228
|
+
uniqueItems?: boolean | undefined;
|
|
213
229
|
} & {
|
|
214
230
|
dataRef?: string | null | undefined;
|
|
215
231
|
':type'?: string | undefined;
|
|
@@ -241,6 +257,9 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
241
257
|
enum?: any[] | undefined;
|
|
242
258
|
} & {
|
|
243
259
|
accept?: string[] | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* @private
|
|
262
|
+
*/
|
|
244
263
|
enforceEnum?: boolean | undefined;
|
|
245
264
|
exclusiveMinimum?: number | undefined;
|
|
246
265
|
exclusiveMaximum?: number | undefined;
|
|
@@ -257,6 +276,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
257
276
|
step?: number | undefined;
|
|
258
277
|
type?: string | undefined;
|
|
259
278
|
validationExpression?: string | undefined;
|
|
279
|
+
uniqueItems?: boolean | undefined;
|
|
260
280
|
} & {
|
|
261
281
|
dataRef?: string | null | undefined;
|
|
262
282
|
':type'?: string | undefined;
|
|
@@ -282,6 +302,9 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
282
302
|
enum?: any[] | undefined;
|
|
283
303
|
} & {
|
|
284
304
|
accept?: string[] | undefined;
|
|
305
|
+
/**
|
|
306
|
+
* @private
|
|
307
|
+
*/
|
|
285
308
|
enforceEnum?: boolean | undefined;
|
|
286
309
|
exclusiveMinimum?: number | undefined;
|
|
287
310
|
exclusiveMaximum?: number | undefined;
|
|
@@ -298,6 +321,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
298
321
|
step?: number | undefined;
|
|
299
322
|
type?: string | undefined;
|
|
300
323
|
validationExpression?: string | undefined;
|
|
324
|
+
uniqueItems?: boolean | undefined;
|
|
301
325
|
} & {
|
|
302
326
|
dataRef?: string | null | undefined;
|
|
303
327
|
':type'?: string | undefined;
|
|
@@ -329,6 +353,9 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
329
353
|
enum?: any[] | undefined;
|
|
330
354
|
} & {
|
|
331
355
|
accept?: string[] | undefined;
|
|
356
|
+
/**
|
|
357
|
+
* @private
|
|
358
|
+
*/
|
|
332
359
|
enforceEnum?: boolean | undefined;
|
|
333
360
|
exclusiveMinimum?: number | undefined;
|
|
334
361
|
exclusiveMaximum?: number | undefined;
|
|
@@ -345,6 +372,7 @@ declare class Form extends Container<FormJson> implements FormModel {
|
|
|
345
372
|
step?: number | undefined;
|
|
346
373
|
type?: string | undefined;
|
|
347
374
|
validationExpression?: string | undefined;
|
|
375
|
+
uniqueItems?: boolean | undefined;
|
|
348
376
|
} & {
|
|
349
377
|
dataRef?: string | null | undefined;
|
|
350
378
|
':type'?: string | undefined;
|
package/lib/Form.js
CHANGED
|
@@ -79,6 +79,7 @@ class Form extends Container_1.default {
|
|
|
79
79
|
this._ids = (0, FormUtils_1.IdGenerator)();
|
|
80
80
|
this._bindToDataModel(new DataGroup_1.default('$form', {}));
|
|
81
81
|
this._initialize();
|
|
82
|
+
this.queueEvent(new controller_1.FormLoad());
|
|
82
83
|
}
|
|
83
84
|
get logger() {
|
|
84
85
|
return this._logger;
|
package/lib/FormInstance.d.ts
CHANGED
|
@@ -14,9 +14,21 @@ export declare const createFormInstance: (formModel: any, callback?: ((f: FormMo
|
|
|
14
14
|
* Validates Form model definition with the given data
|
|
15
15
|
* @param formModel form model definition
|
|
16
16
|
* @param data form data
|
|
17
|
+
* @deprecated use validateFormData
|
|
17
18
|
* @returns `true`, if form is valid against the given form data, `false` otherwise
|
|
18
19
|
*/
|
|
19
20
|
export declare const validateFormInstance: (formModel: any, data: any) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Validates Form model definition with the given data
|
|
23
|
+
* @param formModel form model definition
|
|
24
|
+
* @param data form data
|
|
25
|
+
* @deprecated use validateFormData
|
|
26
|
+
* @returns {messages: [], valid: boolean}
|
|
27
|
+
*/
|
|
28
|
+
export declare const validateFormData: (formModel: any, data: any) => {
|
|
29
|
+
messages: any[];
|
|
30
|
+
valid: boolean;
|
|
31
|
+
};
|
|
20
32
|
/**
|
|
21
33
|
* Helper API to fetch form model definition from an AEM instance
|
|
22
34
|
* @param url URL of the instance
|
package/lib/FormInstance.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
34
|
};
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.fetchForm = exports.validateFormInstance = exports.createFormInstance = void 0;
|
|
36
|
+
exports.fetchForm = exports.validateFormData = exports.validateFormInstance = exports.createFormInstance = void 0;
|
|
37
37
|
const Form_1 = __importStar(require("./Form"));
|
|
38
38
|
const JsonUtils_1 = require("./utils/JsonUtils");
|
|
39
39
|
const Fetch_1 = require("./utils/Fetch");
|
|
@@ -79,6 +79,7 @@ exports.createFormInstance = createFormInstance;
|
|
|
79
79
|
* Validates Form model definition with the given data
|
|
80
80
|
* @param formModel form model definition
|
|
81
81
|
* @param data form data
|
|
82
|
+
* @deprecated use validateFormData
|
|
82
83
|
* @returns `true`, if form is valid against the given form data, `false` otherwise
|
|
83
84
|
*/
|
|
84
85
|
const validateFormInstance = (formModel, data) => {
|
|
@@ -94,6 +95,30 @@ const validateFormInstance = (formModel, data) => {
|
|
|
94
95
|
}
|
|
95
96
|
};
|
|
96
97
|
exports.validateFormInstance = validateFormInstance;
|
|
98
|
+
/**
|
|
99
|
+
* Validates Form model definition with the given data
|
|
100
|
+
* @param formModel form model definition
|
|
101
|
+
* @param data form data
|
|
102
|
+
* @deprecated use validateFormData
|
|
103
|
+
* @returns {messages: [], valid: boolean}
|
|
104
|
+
*/
|
|
105
|
+
const validateFormData = (formModel, data) => {
|
|
106
|
+
try {
|
|
107
|
+
const f = new Form_1.default(Object.assign({}, formModel), new RuleEngine_1.default());
|
|
108
|
+
if (data) {
|
|
109
|
+
f.importData(data);
|
|
110
|
+
}
|
|
111
|
+
const res = f.validate();
|
|
112
|
+
return {
|
|
113
|
+
messages: res,
|
|
114
|
+
valid: res.length === 0
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
throw new Error(e);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
exports.validateFormData = validateFormData;
|
|
97
122
|
/**
|
|
98
123
|
* Helper API to fetch form model definition from an AEM instance
|
|
99
124
|
* @param url URL of the instance
|
|
@@ -109,6 +109,15 @@ export declare class Initialize extends ActionImpl {
|
|
|
109
109
|
*/
|
|
110
110
|
constructor(payload?: any, dispatch?: boolean);
|
|
111
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Implementation of `load` event. The event is when the form initialization is complete
|
|
114
|
+
*/
|
|
115
|
+
export declare class FormLoad extends ActionImpl {
|
|
116
|
+
/**
|
|
117
|
+
* @constructor
|
|
118
|
+
*/
|
|
119
|
+
constructor();
|
|
120
|
+
}
|
|
112
121
|
/**
|
|
113
122
|
* Implementation of `click` event. The event is triggered when user clicks on an element.
|
|
114
123
|
*/
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ADOBE NOR ITS THIRD PARTY PROVIDERS AND PARTNERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Submit = exports.ValidationComplete = exports.Blur = exports.Click = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.Change = exports.ActionImpl = void 0;
|
|
10
|
+
exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Submit = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.Change = exports.ActionImpl = void 0;
|
|
11
11
|
/**
|
|
12
12
|
* Implementation of generic event
|
|
13
13
|
* @private
|
|
@@ -136,6 +136,18 @@ class Initialize extends ActionImpl {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
exports.Initialize = Initialize;
|
|
139
|
+
/**
|
|
140
|
+
* Implementation of `load` event. The event is when the form initialization is complete
|
|
141
|
+
*/
|
|
142
|
+
class FormLoad extends ActionImpl {
|
|
143
|
+
/**
|
|
144
|
+
* @constructor
|
|
145
|
+
*/
|
|
146
|
+
constructor() {
|
|
147
|
+
super({}, 'load', { dispatch: false });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.FormLoad = FormLoad;
|
|
139
151
|
/**
|
|
140
152
|
* Implementation of `click` event. The event is triggered when user clicks on an element.
|
|
141
153
|
*/
|
|
@@ -26,6 +26,14 @@ declare class FunctionRuntimeImpl {
|
|
|
26
26
|
_func: (args: unknown, data: unknown, interpreter: any) => any;
|
|
27
27
|
_signature: never[];
|
|
28
28
|
};
|
|
29
|
+
exportData: {
|
|
30
|
+
_func: (args: unknown, data: unknown, interpreter: any) => any;
|
|
31
|
+
_signature: never[];
|
|
32
|
+
};
|
|
33
|
+
importData: {
|
|
34
|
+
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
35
|
+
_signature: never[];
|
|
36
|
+
};
|
|
29
37
|
submitForm: {
|
|
30
38
|
_func: (args: Array<unknown>, data: unknown, interpreter: any) => {};
|
|
31
39
|
_signature: never[];
|
|
@@ -210,10 +210,28 @@ class FunctionRuntimeImpl {
|
|
|
210
210
|
},
|
|
211
211
|
getData: {
|
|
212
212
|
_func: (args, data, interpreter) => {
|
|
213
|
+
// deprecated. left for backward compatability.
|
|
214
|
+
interpreter.globals.form.logger.warn('The `getData` function is depricated. Use `exportData` instead.');
|
|
213
215
|
return interpreter.globals.form.exportData();
|
|
214
216
|
},
|
|
215
217
|
_signature: []
|
|
216
218
|
},
|
|
219
|
+
exportData: {
|
|
220
|
+
_func: (args, data, interpreter) => {
|
|
221
|
+
return interpreter.globals.form.exportData();
|
|
222
|
+
},
|
|
223
|
+
_signature: []
|
|
224
|
+
},
|
|
225
|
+
importData: {
|
|
226
|
+
_func: (args, data, interpreter) => {
|
|
227
|
+
const inputData = args[0];
|
|
228
|
+
if (typeof inputData === 'object' && inputData !== null) {
|
|
229
|
+
interpreter.globals.form.importData(inputData);
|
|
230
|
+
}
|
|
231
|
+
return {};
|
|
232
|
+
},
|
|
233
|
+
_signature: []
|
|
234
|
+
},
|
|
217
235
|
submitForm: {
|
|
218
236
|
_func: (args, data, interpreter) => {
|
|
219
237
|
// success: string, error: string, submit_as: 'json' | 'multipart' = 'json', data: any = null
|
package/lib/types/Json.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare type ConstraintsJson = TranslationConstraintsJson & {
|
|
|
37
37
|
step?: number;
|
|
38
38
|
type?: string;
|
|
39
39
|
validationExpression?: string;
|
|
40
|
+
uniqueItems?: boolean;
|
|
40
41
|
};
|
|
41
42
|
/** Type for `constraint messages` based on `adaptive form specification` */
|
|
42
43
|
export declare type ConstraintsMessages = {
|
package/lib/types/Json.js
CHANGED
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.constraintProps = exports.translationProps = void 0;
|
|
11
11
|
/** Constant for all properties which can be translated based on `adaptive form specification` */
|
|
12
|
-
exports.translationProps = ['description', 'placeholder', 'enum', 'enumNames', 'label.value'
|
|
12
|
+
exports.translationProps = ['description', 'placeholder', 'enum', 'enumNames', 'label.value', 'constraintMessages.accept',
|
|
13
|
+
'constraintMessages.enum', 'constraintMessages.exclusiveMinimum', 'constraintMessages.exclusiveMaximum', 'constraintMessages.format', 'constraintMessages.maxFileSize', 'constraintMessages.maxLength',
|
|
14
|
+
'constraintMessages.maximum', 'constraintMessages.maxItems', 'constraintMessages.minLength', 'constraintMessages.minimum', 'constraintMessages.minItems', 'constraintMessages.pattern', 'constraintMessages.required',
|
|
15
|
+
'constraintMessages.step', 'constraintMessages.type', 'constraintMessages.validationExpression'];
|
|
13
16
|
/** Constant for all properties which are constraints based on `adaptive form specification` */
|
|
14
17
|
exports.constraintProps = ['accept', 'enum', 'exclusiveMinimum', 'exclusiveMaximum',
|
|
15
18
|
'format', 'maxFileSize', 'maxLength', 'maximum', 'maxItems',
|
|
@@ -22,7 +22,7 @@ export declare const addTranslationId: (input: formElementJson, additionalTransl
|
|
|
22
22
|
* @param key key to return from input object (key could be comma separated, example, label.value)
|
|
23
23
|
* @param defaultValue default value
|
|
24
24
|
*/
|
|
25
|
-
export declare const getOrElse: (input: any, key: string, defaultValue?: any) => any;
|
|
25
|
+
export declare const getOrElse: (input: any, key: string | string[], defaultValue?: any) => any;
|
|
26
26
|
/**
|
|
27
27
|
* @param input
|
|
28
28
|
* @param additionalTranslationProps
|
|
@@ -59,7 +59,15 @@ exports.addTranslationId = addTranslationId;
|
|
|
59
59
|
const _createTranslationId = (input, path, transProps) => {
|
|
60
60
|
Object.entries(input).forEach(([key, value]) => {
|
|
61
61
|
if (typeof value == 'object') {
|
|
62
|
-
|
|
62
|
+
if (input instanceof Array) {
|
|
63
|
+
if (value && 'name' in value) {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
_createTranslationId(value, `${path === '' ? path : path + exports.TRANSLATION_TOKEN}${value.name}`, transProps);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
_createTranslationId(value, ((key === 'items') ? path : `${path === '' ? path : path + exports.TRANSLATION_TOKEN}${key}`), transProps);
|
|
70
|
+
}
|
|
63
71
|
}
|
|
64
72
|
else {
|
|
65
73
|
// set it only if either of type or fieldType properties is present
|
|
@@ -131,7 +139,7 @@ const getOrElse = (input, key, defaultValue = null) => {
|
|
|
131
139
|
if (!key) {
|
|
132
140
|
return defaultValue;
|
|
133
141
|
}
|
|
134
|
-
const arr = key.split('.');
|
|
142
|
+
const arr = Array.isArray(key) ? key : key.split('.');
|
|
135
143
|
let objValue = input, index = 0;
|
|
136
144
|
while (index < arr.length && objValue.hasOwnProperty(arr[index])) {
|
|
137
145
|
objValue = objValue[arr[index]];
|