@bolttech/form-engine-core 0.0.1-beta.15 → 0.0.1-beta.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.
Files changed (2) hide show
  1. package/index.esm.js +26 -24
  2. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Subject, Subscription, combineLatest, startWith, groupBy, mergeMap, debounceTime, filter, map } from 'rxjs';
2
2
  import creditCardType from 'credit-card-type';
3
- import { isNumber as isNumber$1, isNil, isEqual, get, set } from 'lodash';
3
+ import { isNumber as isNumber$1, isEqual, get, isNil, set } from 'lodash';
4
4
  import { getCurrencySymbol } from '@gaignoux/currency';
5
5
 
6
6
  var TMutationEnum;
@@ -142,7 +142,7 @@ function traverseObject(obj, path) {
142
142
  if (typeof item === 'object') {
143
143
  result.push(...traverseObject(item, `${path ? `${path}.` : ``}${key}.${index}`));
144
144
  } else if (typeof item === 'string') {
145
- if (String(item).includes('$')) {
145
+ if (String(item).includes('${')) {
146
146
  // const extractedPath = item.replace(/\$|{|}/g, '').split('.');
147
147
  const extractedOriginPath = `${path ? `${path}.` : ``}${key}`.split('.');
148
148
  result.push(Object.assign(Object.assign({
@@ -158,7 +158,7 @@ function traverseObject(obj, path) {
158
158
  } else if (typeof value === 'object') {
159
159
  result.push(...traverseObject(value, `${path ? `${path}.` : ``}${key}`));
160
160
  } else if (typeof value === 'string') {
161
- if (value.includes('$')) {
161
+ if (value.includes('${')) {
162
162
  // const extractedPath = value.replace(/\$|{|}/g, '').split('.');
163
163
  const destinationPath = `${path ? `${path}.` : ``}${key}`.split('.');
164
164
  result.push(Object.assign(Object.assign({
@@ -2298,7 +2298,7 @@ class FormField {
2298
2298
  dataSubject$,
2299
2299
  mapper
2300
2300
  }) {
2301
- var _a, _b, _c, _d, _e, _f, _g, _h;
2301
+ var _a, _b, _c, _d, _e, _f, _g;
2302
2302
  this.fieldStateSubscription$ = new Subscription();
2303
2303
  this.originalSchema = schemaComponent;
2304
2304
  this.config = {
@@ -2326,10 +2326,6 @@ class FormField {
2326
2326
  this.fieldEventSubject$ = fieldEventSubject$;
2327
2327
  this.dataSubject$ = dataSubject$;
2328
2328
  this._props = schemaComponent.props || {};
2329
- this._value = '';
2330
- this._stateValue = ((_c = this.mapper.events) === null || _c === void 0 ? void 0 : _c.setValue) ? {
2331
- [this.mapper.events.setValue]: ''
2332
- } : {};
2333
2329
  this._metadata = '';
2334
2330
  this.errorsString = '';
2335
2331
  this.errorsList = [];
@@ -2337,9 +2333,9 @@ class FormField {
2337
2333
  this._visibility = true;
2338
2334
  this._api = {
2339
2335
  default: {
2340
- response: ((_f = (_e = (_d = this.apiSchema) === null || _d === void 0 ? void 0 : _d.defaultConfig) === null || _e === void 0 ? void 0 : _e.config) === null || _f === void 0 ? void 0 : _f.fallbackValue) || ''
2336
+ response: ((_e = (_d = (_c = this.apiSchema) === null || _c === void 0 ? void 0 : _c.defaultConfig) === null || _d === void 0 ? void 0 : _d.config) === null || _e === void 0 ? void 0 : _e.fallbackValue) || ''
2341
2337
  },
2342
- named: ((_g = this.apiSchema) === null || _g === void 0 ? void 0 : _g.configs) && Object.keys((_h = this.apiSchema) === null || _h === void 0 ? void 0 : _h.configs).reduce((acc, curr) => {
2338
+ named: ((_f = this.apiSchema) === null || _f === void 0 ? void 0 : _f.configs) && Object.keys((_g = this.apiSchema) === null || _g === void 0 ? void 0 : _g.configs).reduce((acc, curr) => {
2343
2339
  var _a, _b;
2344
2340
  acc[curr] = {
2345
2341
  response: ((_b = (_a = this.apiSchema) === null || _a === void 0 ? void 0 : _a.configs) === null || _b === void 0 ? void 0 : _b[curr].config.fallbackValue) || ''
@@ -2351,6 +2347,7 @@ class FormField {
2351
2347
  this._valid = false;
2352
2348
  this._mounted = true;
2353
2349
  this.initializeObservers();
2350
+ this.value = this.initialValue || '';
2354
2351
  }
2355
2352
  /**
2356
2353
  * method to initialize all recycled Subjects and initialize Observers on field instance creation or rerender
@@ -2390,12 +2387,6 @@ class FormField {
2390
2387
  }) => event), mergeMap(group$ => group$.pipe(debounceTime(this.config.defaultAPIdebounceTimeMS))), filter(() => this.apiSubject$ && !this.apiSubject$.closed)).subscribe(payload => {
2391
2388
  this.apiRequest(payload);
2392
2389
  });
2393
- if (!isNil(this.initialValue)) {
2394
- this.value = this.initialValue;
2395
- this.setFieldValidity({
2396
- event: 'ON_FORM_SUBMIT'
2397
- });
2398
- }
2399
2390
  }
2400
2391
  /**
2401
2392
  * Retrieves the properties associated with the form field.
@@ -2498,6 +2489,23 @@ class FormField {
2498
2489
  set visibility(visible) {
2499
2490
  if (typeof visible === 'undefined' || visible === this.visibility) return;
2500
2491
  this._visibility = visible;
2492
+ /**
2493
+ * I was sure I would not require to gambiarra, but..
2494
+ * in order to ignore an hidden value on a form submit
2495
+ * or revalidate it when it comes back to visibility
2496
+ * I needed to...
2497
+ * I don't recommend setting private properties like this
2498
+ * this will force the field to be valid when it's hidden
2499
+ * and trigger the validation when it's visible
2500
+ */
2501
+ if (!this.visibility) {
2502
+ this.value = '';
2503
+ this._valid = true;
2504
+ } else {
2505
+ this.setFieldValidity({
2506
+ event: 'ON_FIELD_MOUNT'
2507
+ });
2508
+ }
2501
2509
  this.visibilitySubject$.next(this.visibility);
2502
2510
  this.templateSubject$.next({
2503
2511
  key: this.name,
@@ -3211,16 +3219,10 @@ class FormCore {
3211
3219
  const error = validations[validationKey](field.value, structElement.validations);
3212
3220
  if (Array.isArray(structElement.fields)) {
3213
3221
  structElement.fields.forEach(fieldKey => {
3214
- if (!this.fields.has(fieldKey)) console.warn(`failed to update visibility onto field ${fieldKey}`);else {
3215
- this.fields.get(fieldKey).visibility = !error;
3216
- if (error) this.fields.get(fieldKey).value = '';
3217
- }
3222
+ if (!this.fields.has(fieldKey)) console.warn(`failed to update visibility onto field ${fieldKey}`);else this.fields.get(fieldKey).visibility = !error;
3218
3223
  });
3219
3224
  } else if (structElement.fields) {
3220
- if (!this.fields.has(structElement.fields)) console.warn(`failed to update visibility onto field ${structElement.fields}`);else {
3221
- this.fields.get(structElement.fields).visibility = !error;
3222
- if (error) this.fields.get(structElement.fields).value = '';
3223
- }
3225
+ if (!this.fields.has(structElement.fields)) console.warn(`failed to update visibility onto field ${structElement.fields}`);else this.fields.get(structElement.fields).visibility = !error;
3224
3226
  }
3225
3227
  });
3226
3228
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "0.0.1-beta.15",
3
+ "version": "0.0.1-beta.16",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",