tuain-form-manager 1.1.23 → 1.2.0
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/form.js +61 -13
- package/package.json +1 -1
package/lib/form.js
CHANGED
|
@@ -22,6 +22,13 @@ const ROWSELECTION = 'ROWSELECTION';
|
|
|
22
22
|
const DEFAULT_RECORDS_PAGE = 10;
|
|
23
23
|
const RESTRICTED_ATTRIBUTES = ['actions', 'fields', 'recordTables', 'cookiesToSet', 'immutableData', 'returnedFile'];
|
|
24
24
|
|
|
25
|
+
const FIELD_ASSIGN_ATTRIBUTES = [
|
|
26
|
+
'defaultEditable', 'defaultValue', 'alignment', 'required', 'errorCode', 'errorMessage', 'errorType',
|
|
27
|
+
'tooltip', 'info', 'format', 'intrinsicErrorMessage', 'outputOnly', 'captureType', 'title', 'type',
|
|
28
|
+
'maxLength', 'maxValue', 'minLength', 'minValue', 'validateOnServer', 'serverAction', 'visibleLabel',
|
|
29
|
+
'options',
|
|
30
|
+
];
|
|
31
|
+
|
|
25
32
|
const SESSION_ATTRIBUTES = {
|
|
26
33
|
sessionCode: 'sessionCode',
|
|
27
34
|
profileCode: 'profileCode',
|
|
@@ -70,12 +77,12 @@ class Form {
|
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
importExchange(requestData, this);
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
76
|
-
this.
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
80
|
+
this.onAction(START, () => this.start());
|
|
81
|
+
this.onAction(START_OPERATION, () => this.startOperation());
|
|
82
|
+
this.onAction(GETDATA, () => this.getData());
|
|
83
|
+
this.onAction(VALIDATE_FIELD, () => this.executeFieldValidation());
|
|
84
|
+
this.onAction(TABLE_ACCION, () => this.executeTableAction());
|
|
85
|
+
this.onAction(TABLE_GET_DATA, () => this.executeTablePopulate());
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
// eslint-disable-next-line class-methods-use-this
|
|
@@ -189,7 +196,7 @@ class Form {
|
|
|
189
196
|
hideAction(code) { this.setActionAttribute(code, VISIBLE, false); }
|
|
190
197
|
enableAction(code) { this.setActionAttribute(code, DISABLED, false); }
|
|
191
198
|
disableAction(code) { this.setActionAttribute(code, DISABLED, true); }
|
|
192
|
-
|
|
199
|
+
onAction(code, callback) { this._formActions[code] = callback; }
|
|
193
200
|
|
|
194
201
|
showActions(actionArray) {
|
|
195
202
|
const actionNames = (Array.isArray(actionArray)) ? actionArray : [actionArray];
|
|
@@ -236,6 +243,17 @@ class Form {
|
|
|
236
243
|
return inputField;
|
|
237
244
|
}
|
|
238
245
|
|
|
246
|
+
setFieldAttributes(code, attrObj) {
|
|
247
|
+
const field = this.getField(code);
|
|
248
|
+
if (field) {
|
|
249
|
+
Object.entries(attrObj ?? {}).forEach(([attr, value]) => {
|
|
250
|
+
if (FIELD_ASSIGN_ATTRIBUTES.includes(attr)) {
|
|
251
|
+
field[attr] = value;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
239
257
|
setFieldAttribute(fieldCode, attr, value) {
|
|
240
258
|
const fieldObject = this.getField(fieldCode);
|
|
241
259
|
if (fieldObject) { fieldObject[attr] = value; }
|
|
@@ -251,12 +269,12 @@ class Form {
|
|
|
251
269
|
getFieldValue(code) { return this.getField(code)?.fieldValue ?? null; }
|
|
252
270
|
demandField(code) { this.setFieldAttribute(code, REQUIRED, true); }
|
|
253
271
|
giveUpField(code) { this.setFieldAttribute(code, REQUIRED, false); }
|
|
254
|
-
|
|
272
|
+
onFieldValidation(code, callback) { this._fieldValidations[code] = callback; }
|
|
255
273
|
|
|
256
|
-
|
|
274
|
+
onFieldsValidation(fields, callback) {
|
|
257
275
|
if (!Array.isArray(fields) || fields?.length === 0 || !callback) { return; }
|
|
258
276
|
fields?.forEach((code) => {
|
|
259
|
-
this.
|
|
277
|
+
this.onFieldValidation(code, callback);
|
|
260
278
|
});
|
|
261
279
|
}
|
|
262
280
|
|
|
@@ -333,9 +351,9 @@ class Form {
|
|
|
333
351
|
|
|
334
352
|
getTableDefinition(code) { return this._formDefinition?.tables.find(tbl => tbl.tableCode === code) ?? null; }
|
|
335
353
|
getTableConstraints(tableCode) { return this.getTableDefinition(tableCode)?.constraints ?? null; }
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
354
|
+
onTableRowSelection(code, callback) { this.onTableAction(code, ROWSELECTION, callback); }
|
|
355
|
+
onTablePopulate(code, callback) { this._tablePopulate[code] = callback; }
|
|
356
|
+
onTableAction(tableCode, actionCode, callback) {
|
|
339
357
|
if (!this._tableActions[tableCode]) { this._tableActions[tableCode] = {}; }
|
|
340
358
|
this._tableActions[tableCode][actionCode] = callback;
|
|
341
359
|
}
|
|
@@ -672,6 +690,36 @@ class Form {
|
|
|
672
690
|
}
|
|
673
691
|
return errorObject;
|
|
674
692
|
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* @deprecated Use onAction
|
|
696
|
+
*/
|
|
697
|
+
addActionMethod(code, callback) { return this.onAction(code, callback); }
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* @deprecated Use onFieldValidation
|
|
701
|
+
*/
|
|
702
|
+
addFieldValidation(code, callback) { return this.onFieldValidation(code, callback); }
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* @deprecated Use onFieldsValidation
|
|
706
|
+
*/
|
|
707
|
+
addFieldsValidation(fields, callback) { return this.onFieldsValidation(fields, callback); }
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* @deprecated Use onTableRowSelection
|
|
711
|
+
*/
|
|
712
|
+
addTableRowSelection(code, callback) { return this.onTableRowSelection(code, callback); }
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* @deprecated Use onTablePopulate
|
|
716
|
+
*/
|
|
717
|
+
addTablePopulate(code, callback) { return this.onTablePopulate(code, callback); }
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* @deprecated Use onTableAction
|
|
721
|
+
*/
|
|
722
|
+
addTableAction(tableCode, actionCode, callback) { return this.onTableAction(tableCode, actionCode, callback); }
|
|
675
723
|
}
|
|
676
724
|
|
|
677
725
|
module.exports = Form;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tuain-form-manager",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Component library to perform operations on Tuain Development Framework forms to interchange information on web or mobile applications based on the data interchange of abstract forms making trnasformation on the data upon actions required on both sides (front and back)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|