tuain-ng-forms-lib 17.1.35 → 17.1.37
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/esm2022/lib/classes/forms/field.mjs +6 -1
- package/esm2022/lib/classes/forms/form.mjs +26 -8
- package/esm2022/lib/components/forms/basic-form.mjs +32 -1
- package/fesm2022/tuain-ng-forms-lib.mjs +61 -7
- package/fesm2022/tuain-ng-forms-lib.mjs.map +1 -1
- package/lib/classes/forms/field.d.ts +3 -0
- package/lib/classes/forms/form.d.ts +1 -1
- package/lib/components/forms/basic-form.d.ts +3 -0
- package/package.json +1 -1
|
@@ -933,6 +933,7 @@ const attrs$1 = {
|
|
|
933
933
|
visibleLabel: { name: '_visibleLabel', propagate: 'visibleLabel' },
|
|
934
934
|
};
|
|
935
935
|
class FieldDescriptor extends FormElement {
|
|
936
|
+
_customEvent = new Subject();
|
|
936
937
|
_editionFinish = new Subject();
|
|
937
938
|
_editionPartial = new Subject();
|
|
938
939
|
_detailRequest = new Subject();
|
|
@@ -1029,6 +1030,7 @@ class FieldDescriptor extends FormElement {
|
|
|
1029
1030
|
get defaultEditable() { return this._defaultEditable; }
|
|
1030
1031
|
set defaultEditable(editable) { this.setAttr(attrs$1.defaultEditable, editable); }
|
|
1031
1032
|
get detailRequest() { return this._detailRequest; }
|
|
1033
|
+
get customEvent() { return this._customEvent; }
|
|
1032
1034
|
get editionFinish() { return this._editionFinish; }
|
|
1033
1035
|
get editionPartial() { return this._editionPartial; }
|
|
1034
1036
|
get empty() {
|
|
@@ -1246,6 +1248,9 @@ class FieldDescriptor extends FormElement {
|
|
|
1246
1248
|
this.resetError();
|
|
1247
1249
|
this._editionPartial.next({ code: this._fieldCode, intrinsicValidation: true });
|
|
1248
1250
|
}
|
|
1251
|
+
triggerCustomEvent(eventName) {
|
|
1252
|
+
this._customEvent.next({ code: this._fieldCode, eventName });
|
|
1253
|
+
}
|
|
1249
1254
|
notifyEditionFinish() {
|
|
1250
1255
|
const fieldValue = this.value;
|
|
1251
1256
|
this.resetError();
|
|
@@ -2604,15 +2609,33 @@ class FormStructureAndData {
|
|
|
2604
2609
|
}
|
|
2605
2610
|
}
|
|
2606
2611
|
setFieldErrorMessage(code, message) { this.getField(code)?.setErrorMessage(message); }
|
|
2607
|
-
setFieldOptions(code, optionsArray, idAttribute,
|
|
2612
|
+
setFieldOptions(code, optionsArray, idAttribute, valueAttribute, saparator = '-') {
|
|
2608
2613
|
const field = this.getField(code);
|
|
2609
|
-
if (field
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2614
|
+
if (!field) {
|
|
2615
|
+
return;
|
|
2616
|
+
}
|
|
2617
|
+
const newOptions = [];
|
|
2618
|
+
const numSeparators = (Array.isArray(valueAttribute)) ? (valueAttribute.length - 1) : 0;
|
|
2619
|
+
for (let i = 0; i < optionsArray?.length; i++) {
|
|
2620
|
+
const optionItem = optionsArray[i];
|
|
2621
|
+
const fieldOptionId = optionItem?.[idAttribute];
|
|
2622
|
+
let fieldOptionText = '';
|
|
2623
|
+
if (Array.isArray(valueAttribute)) {
|
|
2624
|
+
for (let index = 0; index < valueAttribute.length; index++) {
|
|
2625
|
+
const textPart = valueAttribute[index];
|
|
2626
|
+
fieldOptionText += (index < numSeparators)
|
|
2627
|
+
? `${optionItem?.[textPart]} ${saparator} ` : optionItem?.[textPart];
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
else {
|
|
2631
|
+
fieldOptionText = optionItem?.[valueAttribute];
|
|
2632
|
+
}
|
|
2633
|
+
if (fieldOptionId !== undefined && fieldOptionId !== null
|
|
2634
|
+
&& fieldOptionText !== undefined && fieldOptionText !== null) {
|
|
2635
|
+
newOptions.push({ fieldOptionId, fieldOptionValue: fieldOptionText });
|
|
2636
|
+
}
|
|
2615
2637
|
}
|
|
2638
|
+
field.options = newOptions;
|
|
2616
2639
|
}
|
|
2617
2640
|
getFieldSet(filter, inputCodes, secCode, subCode) {
|
|
2618
2641
|
let codes = [];
|
|
@@ -3078,6 +3101,7 @@ class BasicFormComponent extends FormStructureAndData {
|
|
|
3078
3101
|
_formSectionsInactivate = {};
|
|
3079
3102
|
_formActionsStart = {};
|
|
3080
3103
|
_formActionsFinish = {};
|
|
3104
|
+
_fieldCustomeEvent = {};
|
|
3081
3105
|
_fieldInputValidation = {};
|
|
3082
3106
|
_fieldValidationsStart = {};
|
|
3083
3107
|
_fieldValidationsFinish = {};
|
|
@@ -3137,6 +3161,7 @@ class BasicFormComponent extends FormStructureAndData {
|
|
|
3137
3161
|
this._formSectionsInactivate = {};
|
|
3138
3162
|
this._formActionsStart = {};
|
|
3139
3163
|
this._formActionsFinish = {};
|
|
3164
|
+
this._fieldCustomeEvent = {};
|
|
3140
3165
|
this._fieldInputValidation = {};
|
|
3141
3166
|
this._fieldValidationsStart = {};
|
|
3142
3167
|
this._fieldValidationsFinish = {};
|
|
@@ -3248,6 +3273,10 @@ class BasicFormComponent extends FormStructureAndData {
|
|
|
3248
3273
|
const formFields = this.getFields();
|
|
3249
3274
|
if (Array.isArray(formFields)) {
|
|
3250
3275
|
formFields.forEach(field => {
|
|
3276
|
+
field.customEvent.subscribe(event => {
|
|
3277
|
+
const { code, eventName } = event;
|
|
3278
|
+
this.startFieldCustomEvent(code, eventName);
|
|
3279
|
+
});
|
|
3251
3280
|
field.editionFinish.subscribe(event => {
|
|
3252
3281
|
const { code, intrinsicValidation } = event;
|
|
3253
3282
|
this.startFieldValidation(code, intrinsicValidation);
|
|
@@ -3608,6 +3637,15 @@ class BasicFormComponent extends FormStructureAndData {
|
|
|
3608
3637
|
this._fieldInputValidation[code].push({ callback, properties });
|
|
3609
3638
|
});
|
|
3610
3639
|
}
|
|
3640
|
+
onFieldCustomEvent(codes, callback, properties = null) {
|
|
3641
|
+
const fieldSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
|
|
3642
|
+
fieldSet.forEach((code) => {
|
|
3643
|
+
if (!this._fieldCustomeEvent[code]) {
|
|
3644
|
+
this._fieldCustomeEvent[code] = [];
|
|
3645
|
+
}
|
|
3646
|
+
this._fieldCustomeEvent[code].push({ callback, properties });
|
|
3647
|
+
});
|
|
3648
|
+
}
|
|
3611
3649
|
onFieldValidationStart(codes, callback, properties = null) {
|
|
3612
3650
|
const fieldSet = (Array.isArray(codes)) ? codes : (codes ? [codes] : []);
|
|
3613
3651
|
fieldSet.forEach((code) => {
|
|
@@ -3644,6 +3682,22 @@ class BasicFormComponent extends FormStructureAndData {
|
|
|
3644
3682
|
}
|
|
3645
3683
|
return true;
|
|
3646
3684
|
}
|
|
3685
|
+
async startFieldCustomEvent(code, eventName) {
|
|
3686
|
+
this.notifyFormActivity();
|
|
3687
|
+
const fieldToTrigger = this.getField(code);
|
|
3688
|
+
if (!fieldToTrigger) {
|
|
3689
|
+
return;
|
|
3690
|
+
}
|
|
3691
|
+
const eventHandlerCallbacks = this._fieldCustomeEvent[code];
|
|
3692
|
+
if (eventHandlerCallbacks) {
|
|
3693
|
+
const clientEventPromises = [];
|
|
3694
|
+
for (const eventHandlerMethod of eventHandlerCallbacks) {
|
|
3695
|
+
const { callback, properties } = eventHandlerMethod;
|
|
3696
|
+
const clientEventPromise = callback(eventName, fieldToTrigger);
|
|
3697
|
+
clientEventPromises.push(clientEventPromise);
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
}
|
|
3647
3701
|
async startFieldValidation(code, intrinsicValidation = true) {
|
|
3648
3702
|
this.notifyFormActivity();
|
|
3649
3703
|
const fieldToValidate = this.getField(code);
|