@bolttech/form-engine-core 0.0.1-beta.25 → 0.0.1-beta.26

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 CHANGED
@@ -1933,7 +1933,7 @@ const conditions = (value, validations) => {
1933
1933
  * Validates if a date string matches a specific date format.
1934
1934
  * The function accepts strings with '/' or '-' separators and removes them before validating the format.
1935
1935
  *
1936
- * @param {string} string - The date string to be validated. It can contain '/' or '-' separators.
1936
+ * @param {string} value - The date string to be validated. It can contain '/' or '-' separators.
1937
1937
  * @param {string} format - The expected date format. It can be one of the following:
1938
1938
  * 'DDMMYYYY', 'YYYYMMDD', 'YYYYDDMM', 'MMDDYYYY',
1939
1939
  * 'DMYYYY', 'YYYYMD', 'YYYYDM', 'MDYYYY'.
@@ -2096,18 +2096,17 @@ const date = (value, validations) => {
2096
2096
  }
2097
2097
  const originValue = validations.date.origin.value || value;
2098
2098
  const mappedValue = dateRearrangeMapper[(_e = validations.date) === null || _e === void 0 ? void 0 : _e.origin.format](originValue).toString();
2099
- if (invalidStringDate(mappedValue, (_f = validations.date) === null || _f === void 0 ? void 0 : _f.origin.format)) return false;
2100
2099
  let originDate = new Date(mappedValue);
2101
2100
  let targetDate = new Date();
2102
2101
  let target = new Date();
2103
- if ((_h = (_g = validations.date) === null || _g === void 0 ? void 0 : _g.target) === null || _h === void 0 ? void 0 : _h.format) {
2104
- target = new Date(dateRearrangeMapper[(_k = (_j = validations.date) === null || _j === void 0 ? void 0 : _j.target) === null || _k === void 0 ? void 0 : _k.format](validations.date.target.value).toString());
2102
+ if ((_g = (_f = validations.date) === null || _f === void 0 ? void 0 : _f.target) === null || _g === void 0 ? void 0 : _g.format) {
2103
+ target = new Date(dateRearrangeMapper[(_j = (_h = validations.date) === null || _h === void 0 ? void 0 : _h.target) === null || _j === void 0 ? void 0 : _j.format](validations.date.target.value).toString());
2105
2104
  targetDate = target;
2106
2105
  }
2107
2106
  if (validations.date.origin.intervals) {
2108
2107
  targetDate = getIntervalsDate(originDate, validations.date.origin.intervals);
2109
2108
  const date = new Date();
2110
- if (((_l = validations.date.target) === null || _l === void 0 ? void 0 : _l.value) && target) {
2109
+ if (((_k = validations.date.target) === null || _k === void 0 ? void 0 : _k.value) && target) {
2111
2110
  date.setDate(target.getDate());
2112
2111
  date.setMonth(target.getMonth());
2113
2112
  }
@@ -2116,6 +2115,9 @@ const date = (value, validations) => {
2116
2115
  if (validations.date.onlyValidDate && (!(targetDate instanceof Date && isFinite(targetDate)) || !(targetDate instanceof Date && isFinite(originDate)) || originValue.length < 8)) {
2117
2116
  return true;
2118
2117
  }
2118
+ if (invalidStringDate(mappedValue, (_l = validations.date) === null || _l === void 0 ? void 0 : _l.origin.format)) {
2119
+ return false;
2120
+ }
2119
2121
  const originTimestamp = originDate.getTime();
2120
2122
  const targetTimestamp = targetDate.getTime();
2121
2123
  const operationsMapper = {
@@ -2126,7 +2128,7 @@ const date = (value, validations) => {
2126
2128
  '===': originTimestamp === targetTimestamp,
2127
2129
  '!==': originTimestamp !== targetTimestamp
2128
2130
  };
2129
- return !operationsMapper[(_m = validations.date) === null || _m === void 0 ? void 0 : _m.operator];
2131
+ return operationsMapper[(_m = validations.date) === null || _m === void 0 ? void 0 : _m.operator];
2130
2132
  };
2131
2133
  /**
2132
2134
  * @function validDate
@@ -2155,12 +2157,8 @@ const validDate = (value, validations) => {
2155
2157
  const month = parseInt(dateParts[0], 10) - 1; // Month is zero-based
2156
2158
  const day = parseInt(dateParts[1], 10);
2157
2159
  const date = new Date(year, month, day);
2158
- /* This line is here because we need to guarantee that the field will not be valid while typing,
2159
- * that is, imagine the scenario where the user wants to type 1995, when typing 19 or 199,
2160
- * the function returns valid, as there is a year 19 or 199.
2161
- */
2162
2160
  if (date.getFullYear() < 1900) {
2163
- return true;
2161
+ return false;
2164
2162
  }
2165
2163
  // Check if the date is valid
2166
2164
  const isValidDate = date.getFullYear() === year && date.getMonth() === month && date.getDate() === day;
@@ -3321,6 +3319,18 @@ class FormCore {
3321
3319
  }
3322
3320
  });
3323
3321
  }
3322
+ setFieldVisibility(field, hasError, showOnlyIfTrue) {
3323
+ console.log('setFieldVisibility:', {
3324
+ field,
3325
+ hasError,
3326
+ showOnlyIfTrue
3327
+ });
3328
+ if (!this.fields.has(field)) {
3329
+ console.warn(`failed to update visibility onto field ${field}`);
3330
+ } else {
3331
+ this.fields.get(field).visibility = showOnlyIfTrue ? hasError : !hasError;
3332
+ }
3333
+ }
3324
3334
  /**
3325
3335
  * Validates visibility conditions for a given event and updates field visibility accordingly.
3326
3336
  *
@@ -3334,17 +3344,25 @@ class FormCore {
3334
3344
  }) {
3335
3345
  const field = this.fields.get(key);
3336
3346
  const structVisibility = field === null || field === void 0 ? void 0 : field.visibilityConditions;
3337
- if (!structVisibility || !(structVisibility === null || structVisibility === void 0 ? void 0 : structVisibility.some(config => config.events.includes(event)))) return;
3347
+ if (!structVisibility || !(structVisibility === null || structVisibility === void 0 ? void 0 : structVisibility.some(config => config.events.includes(event)))) {
3348
+ return;
3349
+ }
3338
3350
  structVisibility.forEach(structElement => {
3339
3351
  if (!structElement.events.includes(event)) return;
3340
3352
  Object.keys(structElement.validations).forEach(validationKey => {
3341
3353
  const error = handleValidation(field.value, structElement.validations, validations, validationKey);
3354
+ console.log('validateVisibility: ', {
3355
+ value: field === null || field === void 0 ? void 0 : field.value,
3356
+ validationKey,
3357
+ error,
3358
+ showCondition: !!(field.value && structElement.showOnlyIfTrue)
3359
+ });
3342
3360
  if (Array.isArray(structElement.fields)) {
3343
3361
  structElement.fields.forEach(fieldKey => {
3344
- if (!this.fields.has(fieldKey)) console.warn(`failed to update visibility onto field ${fieldKey}`);else this.fields.get(fieldKey).visibility = structElement.showOnlyIfTrue ? error : !error;
3362
+ this.setFieldVisibility(fieldKey, error, !!(field.value && structElement.showOnlyIfTrue));
3345
3363
  });
3346
3364
  } else if (structElement.fields) {
3347
- if (!this.fields.has(structElement.fields)) console.warn(`failed to update visibility onto field ${structElement.fields}`);else this.fields.get(structElement.fields).visibility = structElement.showOnlyIfTrue ? error : !error;
3365
+ this.setFieldVisibility(structElement.fields, error, !!(field.value && structElement.showOnlyIfTrue));
3348
3366
  }
3349
3367
  });
3350
3368
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "0.0.1-beta.25",
3
+ "version": "0.0.1-beta.26",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",
@@ -139,6 +139,7 @@ declare class FormCore {
139
139
  * @private
140
140
  */
141
141
  private static checkIndexes;
142
+ private setFieldVisibility;
142
143
  /**
143
144
  * Validates visibility conditions for a given event and updates field visibility accordingly.
144
145
  *