kwikid-forms 0.1.14 → 0.1.16
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/bundles/kwikid-forms.umd.js +516 -336
- package/bundles/kwikid-forms.umd.js.map +1 -1
- package/esm2015/lib/renderer/form-view/definitions/form-view.apis.definition.js +1 -1
- package/esm2015/lib/renderer/form-view/form-view.component.js +52 -51
- package/esm2015/lib/renderer/form-view/helpers/form-view.apis.helper.js +69 -2
- package/esm2015/lib/renderer/renderer.component.js +9 -9
- package/fesm2015/kwikid-forms.js +127 -59
- package/fesm2015/kwikid-forms.js.map +1 -1
- package/lib/renderer/form-view/definitions/form-view.apis.definition.d.ts +10 -1
- package/lib/renderer/form-view/form-view.component.d.ts +1 -1
- package/lib/renderer/form-view/helpers/form-view.apis.helper.d.ts +2 -0
- package/lib/renderer/renderer.component.d.ts +1 -1
- package/package.json +1 -1
package/fesm2015/kwikid-forms.js
CHANGED
|
@@ -682,6 +682,67 @@ class Apis {
|
|
|
682
682
|
return this._object.FIELD_CONFIG;
|
|
683
683
|
});
|
|
684
684
|
}
|
|
685
|
+
setRequestHeaders() {
|
|
686
|
+
var _a, _b, _c, _d;
|
|
687
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
688
|
+
if (checkObjectKeyExists(this._request, "headers")) {
|
|
689
|
+
if (checkObjectKeyExists(this._request.headers, "params")) {
|
|
690
|
+
let params = this._request.headers.params;
|
|
691
|
+
let paramIndex = 0;
|
|
692
|
+
for (let param of params) {
|
|
693
|
+
let sources = param.sources;
|
|
694
|
+
let sourceIndex = 0;
|
|
695
|
+
for (let source of sources) {
|
|
696
|
+
const sources = new Source(this._object);
|
|
697
|
+
const value = sources.getValueFromSource(source);
|
|
698
|
+
// Set the Value of current source.
|
|
699
|
+
this._object.FIELD_CONFIG = setValueToObjectPath(this._object.FIELD_CONFIG, `api.request.headers.params[${paramIndex}].sources[${sourceIndex}].value`, value);
|
|
700
|
+
const validation = source.validation;
|
|
701
|
+
const triggers = (_a = validation === null || validation === void 0 ? void 0 : validation.triggers) !== null && _a !== void 0 ? _a : [];
|
|
702
|
+
const rules = (_b = validation === null || validation === void 0 ? void 0 : validation.rules) !== null && _b !== void 0 ? _b : [];
|
|
703
|
+
const actions = (_d = (_c = validation) === null || _c === void 0 ? void 0 : _c.actions) !== null && _d !== void 0 ? _d : [];
|
|
704
|
+
const rulesMapping = new Rule(rules, this._object).mapping();
|
|
705
|
+
for (let action of actions) {
|
|
706
|
+
const conditionEvaluation = new Condition(action.condition, rulesMapping).evaluate();
|
|
707
|
+
if (conditionEvaluation) {
|
|
708
|
+
const actions = new Action(action, rulesMapping, this._object, this._takeAction);
|
|
709
|
+
yield actions.execute();
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
sourceIndex++;
|
|
713
|
+
}
|
|
714
|
+
paramIndex++;
|
|
715
|
+
}
|
|
716
|
+
return this._object.FIELD_CONFIG;
|
|
717
|
+
}
|
|
718
|
+
else {
|
|
719
|
+
return this._object.FIELD_CONFIG;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
return this._object.FIELD_CONFIG;
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
validateRequestHeaders() {
|
|
728
|
+
var _a;
|
|
729
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
730
|
+
const headers = this._request.headers;
|
|
731
|
+
const validation = headers.validation;
|
|
732
|
+
const triggers = validation.triggers;
|
|
733
|
+
const rules = validation.rules;
|
|
734
|
+
const actions = (_a = validation) === null || _a === void 0 ? void 0 : _a.actions;
|
|
735
|
+
const rulesMapping = new Rule(rules, this._object).mapping();
|
|
736
|
+
for (let action of actions) {
|
|
737
|
+
const conditionSuccess = new Condition(action.condition, rulesMapping).evaluate();
|
|
738
|
+
if (conditionSuccess) {
|
|
739
|
+
const actions = new Action(action, rulesMapping, this._object, this._takeAction);
|
|
740
|
+
yield actions.execute();
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return this._object.FIELD_CONFIG;
|
|
744
|
+
});
|
|
745
|
+
}
|
|
685
746
|
validateResponse() {
|
|
686
747
|
return __awaiter(this, void 0, void 0, function* () {
|
|
687
748
|
const validation = this._response.validation;
|
|
@@ -706,6 +767,12 @@ __decorate([
|
|
|
706
767
|
__decorate([
|
|
707
768
|
logMethod
|
|
708
769
|
], Apis.prototype, "validateRequestBody", null);
|
|
770
|
+
__decorate([
|
|
771
|
+
logMethod
|
|
772
|
+
], Apis.prototype, "setRequestHeaders", null);
|
|
773
|
+
__decorate([
|
|
774
|
+
logMethod
|
|
775
|
+
], Apis.prototype, "validateRequestHeaders", null);
|
|
709
776
|
__decorate([
|
|
710
777
|
logMethod
|
|
711
778
|
], Apis.prototype, "validateResponse", null);
|
|
@@ -845,9 +912,7 @@ class KwikIDFormViewComponent {
|
|
|
845
912
|
PREVIOUS_FORM_DATA: this.previousFormData,
|
|
846
913
|
ALL_FORMS_DATA: this.allFormsData
|
|
847
914
|
}, this.takeAction.bind(this));
|
|
848
|
-
|
|
849
|
-
yield validations.validate(field.validation);
|
|
850
|
-
}))();
|
|
915
|
+
yield validations.validate(field.validation);
|
|
851
916
|
}
|
|
852
917
|
if (checkObjectKeyExists(field, "connectedElements")) {
|
|
853
918
|
this.handleConnectedElements({
|
|
@@ -1025,6 +1090,7 @@ class KwikIDFormViewComponent {
|
|
|
1025
1090
|
});
|
|
1026
1091
|
}
|
|
1027
1092
|
handleOnClickApiCall(e) {
|
|
1093
|
+
var _a;
|
|
1028
1094
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1029
1095
|
let field = getFormFieldByKey(this.formFields, e.key);
|
|
1030
1096
|
if (field.type === "api-call") {
|
|
@@ -1042,6 +1108,8 @@ class KwikIDFormViewComponent {
|
|
|
1042
1108
|
PREVIOUS_FORM_DATA: this.previousFormData,
|
|
1043
1109
|
ALL_FORMS_DATA: this.allFormsData
|
|
1044
1110
|
}, this.takeAction.bind(this));
|
|
1111
|
+
field = yield apis.setRequestHeaders();
|
|
1112
|
+
field = yield apis.validateRequestHeaders();
|
|
1045
1113
|
field = yield apis.setRequestBody();
|
|
1046
1114
|
field = yield apis.validateRequestBody();
|
|
1047
1115
|
if (field.api.request.body.validation.is_valid) {
|
|
@@ -1051,7 +1119,7 @@ class KwikIDFormViewComponent {
|
|
|
1051
1119
|
request: {
|
|
1052
1120
|
mode: "POST",
|
|
1053
1121
|
body: field.api.request.body.value,
|
|
1054
|
-
headers: {},
|
|
1122
|
+
headers: (_a = field.api.request.headers.value) !== null && _a !== void 0 ? _a : {},
|
|
1055
1123
|
url: field.api.request.url
|
|
1056
1124
|
}
|
|
1057
1125
|
});
|
|
@@ -1078,60 +1146,60 @@ class KwikIDFormViewComponent {
|
|
|
1078
1146
|
});
|
|
1079
1147
|
}
|
|
1080
1148
|
handleOnClickSaveForm(e) {
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
if (field.
|
|
1085
|
-
|
|
1149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1150
|
+
let formData = this.formGroup.getRawValue();
|
|
1151
|
+
for (let field of this.formFields) {
|
|
1152
|
+
if (field.isFormElement) {
|
|
1153
|
+
if (field.hidden) {
|
|
1154
|
+
delete formData[field.key];
|
|
1155
|
+
}
|
|
1156
|
+
else {
|
|
1157
|
+
formData[field.key] = convertFormFieldValueToStandardFormat(field, formData[field.key]);
|
|
1158
|
+
}
|
|
1086
1159
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1160
|
+
}
|
|
1161
|
+
if (this.formGroup.invalid) {
|
|
1162
|
+
const controls = new FormValidation().getFormFieldsInvalidControls(this.formGroup);
|
|
1163
|
+
let firstFieldWithError = "";
|
|
1164
|
+
for (let control of controls) {
|
|
1165
|
+
if (control.invalid && isEmptyValue(firstFieldWithError)) {
|
|
1166
|
+
firstFieldWithError = control.key;
|
|
1167
|
+
}
|
|
1168
|
+
this.formFields = showFormFieldError(this.formFields, this.formGroup.controls[control.key].errors, control.key, control.invalid);
|
|
1089
1169
|
}
|
|
1170
|
+
this.toggleErrorNotification(true);
|
|
1171
|
+
setTimeout(() => {
|
|
1172
|
+
this.toggleErrorNotification(false);
|
|
1173
|
+
}, 3000);
|
|
1174
|
+
return;
|
|
1090
1175
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
}, this.takeAction.bind(this));
|
|
1102
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
1176
|
+
for (let field of this.formFields) {
|
|
1177
|
+
if (field.isFormElement &&
|
|
1178
|
+
field.validation.triggers.includes("ON_SAVE")) {
|
|
1179
|
+
const validations = new Validation({
|
|
1180
|
+
FIELD_CONFIG: field,
|
|
1181
|
+
FORM_FIELDS: this.formFields,
|
|
1182
|
+
FORM_DATA: this.formData,
|
|
1183
|
+
PREVIOUS_FORM_DATA: this.previousFormData,
|
|
1184
|
+
ALL_FORMS_DATA: this.allFormsData
|
|
1185
|
+
}, this.takeAction.bind(this));
|
|
1103
1186
|
yield validations.validate(field.validation);
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1187
|
+
if (!field.validation.is_valid) {
|
|
1188
|
+
this.toggleErrorNotification(true);
|
|
1189
|
+
setTimeout(() => {
|
|
1190
|
+
this.toggleErrorNotification(false);
|
|
1191
|
+
}, 3000);
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1111
1194
|
}
|
|
1112
1195
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
firstFieldWithError = control.key;
|
|
1120
|
-
}
|
|
1121
|
-
this.formFields = showFormFieldError(this.formFields, this.formGroup.controls[control.key].errors, control.key, control.invalid);
|
|
1122
|
-
}
|
|
1123
|
-
this.toggleErrorNotification(true);
|
|
1124
|
-
setTimeout(() => {
|
|
1125
|
-
this.toggleErrorNotification(false);
|
|
1126
|
-
}, 3000);
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1129
|
-
Object.keys(formData).map((key) => {
|
|
1130
|
-
if (isEmptyValue(formData[key])) {
|
|
1131
|
-
formData[key] = "";
|
|
1132
|
-
}
|
|
1196
|
+
Object.keys(formData).map((key) => {
|
|
1197
|
+
if (isEmptyValue(formData[key])) {
|
|
1198
|
+
formData[key] = "";
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
this.onClickSaveForm.emit({ formConfig: this.formConfig, data: formData });
|
|
1133
1202
|
});
|
|
1134
|
-
this.onClickSaveForm.emit({ formConfig: this.formConfig, data: formData });
|
|
1135
1203
|
}
|
|
1136
1204
|
toggleErrorNotification(show) {
|
|
1137
1205
|
this.showErrorNotification = show;
|
|
@@ -2659,12 +2727,12 @@ class KwikIDFormsRendererComponent {
|
|
|
2659
2727
|
* @param e any
|
|
2660
2728
|
*/
|
|
2661
2729
|
handleOnClickSubmitForms(e) {
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2730
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2731
|
+
if (this.userConfig.userFormFieldsConfig.validation) {
|
|
2732
|
+
const validations = new Validation({
|
|
2733
|
+
FORMS_LIST: this.formsList,
|
|
2734
|
+
ALL_FORMS_DATA: this.formsData
|
|
2735
|
+
}, this.takeAction.bind(this));
|
|
2668
2736
|
yield validations.validate(this.userConfig.userFormFieldsConfig.validation);
|
|
2669
2737
|
if (this.userConfig.userFormFieldsConfig.status === "completed") {
|
|
2670
2738
|
this.onClickSubmit.emit(e);
|
|
@@ -2675,8 +2743,8 @@ class KwikIDFormsRendererComponent {
|
|
|
2675
2743
|
this.toggleErrorNotification(false);
|
|
2676
2744
|
}, 3000);
|
|
2677
2745
|
}
|
|
2678
|
-
}
|
|
2679
|
-
}
|
|
2746
|
+
}
|
|
2747
|
+
});
|
|
2680
2748
|
}
|
|
2681
2749
|
/**
|
|
2682
2750
|
* Miscellaneous Methods
|