@bolttech/form-engine-core 1.0.0-beta.12 → 1.0.0-beta.14
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/index.esm.js +29 -20
- package/package.json +1 -1
- package/src/managers/field.d.ts +8 -0
package/index.esm.js
CHANGED
|
@@ -72,11 +72,12 @@ function makeRequest(method, url, headers, body, queryParams) {
|
|
|
72
72
|
return new Promise(function (resolve, reject) {
|
|
73
73
|
const xhr = new XMLHttpRequest();
|
|
74
74
|
if (queryParams) {
|
|
75
|
-
const
|
|
75
|
+
const [baseUrl, existingParamsString] = url.split('?');
|
|
76
|
+
const searchParams = new URLSearchParams(existingParamsString);
|
|
76
77
|
Object.keys(queryParams).forEach(param => {
|
|
77
|
-
|
|
78
|
+
searchParams.append(param, queryParams[param]);
|
|
78
79
|
});
|
|
79
|
-
url =
|
|
80
|
+
url = `${baseUrl}?${searchParams.toString()}`;
|
|
80
81
|
}
|
|
81
82
|
xhr.open(method, url, true);
|
|
82
83
|
if (headers) {
|
|
@@ -2733,9 +2734,7 @@ class FormField {
|
|
|
2733
2734
|
set valid(valid) {
|
|
2734
2735
|
if (typeof valid !== 'boolean' && this.valid === valid) return;
|
|
2735
2736
|
this._valid = valid;
|
|
2736
|
-
this.
|
|
2737
|
-
fieldTrigger: this.name
|
|
2738
|
-
});
|
|
2737
|
+
this.triggerFieldValidNotification();
|
|
2739
2738
|
}
|
|
2740
2739
|
/**
|
|
2741
2740
|
* Retrieves the validity status of the form field.
|
|
@@ -2745,6 +2744,18 @@ class FormField {
|
|
|
2745
2744
|
get valid() {
|
|
2746
2745
|
return this._valid;
|
|
2747
2746
|
}
|
|
2747
|
+
/**
|
|
2748
|
+
* triggers field valid notification to handle the form instance valid notification
|
|
2749
|
+
*
|
|
2750
|
+
* Note: since form unmount can occur before field unmount, this subject might already be closed by form instance
|
|
2751
|
+
* quick workaround is to check if the subject is already closed before emitting
|
|
2752
|
+
* if form instance onValid or template form.valid doesn't work properly, might be due to this workaround
|
|
2753
|
+
*/
|
|
2754
|
+
triggerFieldValidNotification() {
|
|
2755
|
+
!this.fieldValidNotification$.closed && this.fieldValidNotification$.next({
|
|
2756
|
+
fieldTrigger: this.name
|
|
2757
|
+
});
|
|
2758
|
+
}
|
|
2748
2759
|
/**
|
|
2749
2760
|
* Retrieves the error messages associated with the form field.
|
|
2750
2761
|
*
|
|
@@ -3113,9 +3124,7 @@ class FormField {
|
|
|
3113
3124
|
this.propsSubject$.unsubscribe();
|
|
3114
3125
|
this.errorSubject$.unsubscribe();
|
|
3115
3126
|
this.apiEventQueueSubject$.unsubscribe();
|
|
3116
|
-
|
|
3117
|
-
fieldTrigger: this.name
|
|
3118
|
-
});
|
|
3127
|
+
this.triggerFieldValidNotification();
|
|
3119
3128
|
}
|
|
3120
3129
|
/**
|
|
3121
3130
|
* Subscribes to changes in the field state and executes the provided callback function.
|
|
@@ -3226,7 +3235,6 @@ class FormCore {
|
|
|
3226
3235
|
key,
|
|
3227
3236
|
status
|
|
3228
3237
|
}) {
|
|
3229
|
-
var _a;
|
|
3230
3238
|
if (status) {
|
|
3231
3239
|
const field = this.fields.get(key);
|
|
3232
3240
|
if (!field) {
|
|
@@ -3246,15 +3254,9 @@ class FormCore {
|
|
|
3246
3254
|
scope: 'iVars',
|
|
3247
3255
|
event: 'ON_IVARS'
|
|
3248
3256
|
});
|
|
3249
|
-
if (!this.queuedInitialValues.has(key)) {
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
value: typeof propValue === 'string' && !propValue.includes('${') ? propValue : '',
|
|
3253
|
-
event: 'ON_FIELD_MOUNT'
|
|
3254
|
-
}) : field.emitEvents({
|
|
3255
|
-
event: 'ON_FIELD_MOUNT'
|
|
3256
|
-
});
|
|
3257
|
-
}
|
|
3257
|
+
if (!this.queuedInitialValues.has(key)) field.emitEvents({
|
|
3258
|
+
event: 'ON_FIELD_MOUNT'
|
|
3259
|
+
});
|
|
3258
3260
|
this.checkFieldEventQueues(key);
|
|
3259
3261
|
}
|
|
3260
3262
|
}
|
|
@@ -3861,12 +3863,18 @@ class FormCore {
|
|
|
3861
3863
|
fieldSchema,
|
|
3862
3864
|
mapperElement
|
|
3863
3865
|
}) {
|
|
3864
|
-
var _a;
|
|
3866
|
+
var _a, _b, _c, _d;
|
|
3865
3867
|
if (this.fields.has(fieldSchema.name)) {
|
|
3866
3868
|
throw new Error(`field name ${fieldSchema.name} already defined`);
|
|
3867
3869
|
}
|
|
3868
3870
|
const mapper = mapperElement || ((_a = this.mappers) === null || _a === void 0 ? void 0 : _a.get(fieldSchema.component));
|
|
3869
3871
|
if (!mapper) throw new Error(`mapper not found for ${fieldSchema.component}, add it to the mappers configuration`);
|
|
3872
|
+
if ((_b = mapper.events) === null || _b === void 0 ? void 0 : _b.setValue) {
|
|
3873
|
+
const initialValue = (_c = fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.props) === null || _c === void 0 ? void 0 : _c[(_d = mapper === null || mapper === void 0 ? void 0 : mapper.events) === null || _d === void 0 ? void 0 : _d.setValue];
|
|
3874
|
+
if (!(typeof initialValue === 'undefined') && !this.queuedInitialValues.has(fieldSchema.name) && !(typeof initialValue === 'string' && initialValue.includes('${'))) {
|
|
3875
|
+
this.queuedInitialValues.set(fieldSchema.name, cloneDeep(initialValue));
|
|
3876
|
+
}
|
|
3877
|
+
}
|
|
3870
3878
|
this.fields.set(fieldSchema.name, new FormField({
|
|
3871
3879
|
schemaComponent: fieldSchema,
|
|
3872
3880
|
mapper,
|
|
@@ -4123,6 +4131,7 @@ class FormCore {
|
|
|
4123
4131
|
this.templateSubscription$.unsubscribe();
|
|
4124
4132
|
this.fieldEventSubject$.unsubscribe();
|
|
4125
4133
|
this.dataSubject$.unsubscribe();
|
|
4134
|
+
this.formValidNotification$.unsubscribe();
|
|
4126
4135
|
this.fieldValidNotification$.unsubscribe();
|
|
4127
4136
|
this.fields.forEach(field => field.destroyField());
|
|
4128
4137
|
}
|
package/package.json
CHANGED
package/src/managers/field.d.ts
CHANGED
|
@@ -191,6 +191,14 @@ declare class FormField {
|
|
|
191
191
|
* @returns {boolean} - The validity status of the form field.
|
|
192
192
|
*/
|
|
193
193
|
get valid(): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* triggers field valid notification to handle the form instance valid notification
|
|
196
|
+
*
|
|
197
|
+
* Note: since form unmount can occur before field unmount, this subject might already be closed by form instance
|
|
198
|
+
* quick workaround is to check if the subject is already closed before emitting
|
|
199
|
+
* if form instance onValid or template form.valid doesn't work properly, might be due to this workaround
|
|
200
|
+
*/
|
|
201
|
+
triggerFieldValidNotification(): void;
|
|
194
202
|
/**
|
|
195
203
|
* Retrieves the error messages associated with the form field.
|
|
196
204
|
*
|