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

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
@@ -2157,8 +2157,18 @@ const validDate = (value, validations) => {
2157
2157
  const month = parseInt(dateParts[0], 10) - 1; // Month is zero-based
2158
2158
  const day = parseInt(dateParts[1], 10);
2159
2159
  const date = new Date(year, month, day);
2160
- if (date.getFullYear() < 1900) {
2161
- return false;
2160
+ /*
2161
+ * Motivation: due to the scenario in which a date field may be 'typeable',
2162
+ * we need to ensure that dates less than a thousand and such years are valid.
2163
+ * E.g.: user types 13-07-199 (without this condition, it becomes a valid date, as 199 is a valid year)
2164
+ *
2165
+ * Ps: 150 is a valid value for now, as we still cannot live more than that, from the
2166
+ * the moment we start to live longer, we can rethink this.
2167
+ */
2168
+ const today = new Date();
2169
+ today.setFullYear(today.getFullYear() - 150);
2170
+ if (date.getFullYear() < today.getFullYear()) {
2171
+ return true;
2162
2172
  }
2163
2173
  // Check if the date is valid
2164
2174
  const isValidDate = date.getFullYear() === year && date.getMonth() === month && date.getDate() === day;
@@ -3319,12 +3329,15 @@ class FormCore {
3319
3329
  }
3320
3330
  });
3321
3331
  }
3332
+ /**
3333
+ * @internal
3334
+ * Update field visibility accordingly.
3335
+ *
3336
+ * @param {string} field - Field name to be updated.
3337
+ * @param {boolean} hasError - Condition to be used as visibility.
3338
+ * @param {boolean|undefined} showOnlyIfTrue - Flag to be considered when update field visibility. If it's true, then considered error, if it's false, always considered the opposite.
3339
+ */
3322
3340
  setFieldVisibility(field, hasError, showOnlyIfTrue) {
3323
- console.log('setFieldVisibility:', {
3324
- field,
3325
- hasError,
3326
- showOnlyIfTrue
3327
- });
3328
3341
  if (!this.fields.has(field)) {
3329
3342
  console.warn(`failed to update visibility onto field ${field}`);
3330
3343
  } else {
@@ -3351,12 +3364,6 @@ class FormCore {
3351
3364
  if (!structElement.events.includes(event)) return;
3352
3365
  Object.keys(structElement.validations).forEach(validationKey => {
3353
3366
  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
- });
3360
3367
  if (Array.isArray(structElement.fields)) {
3361
3368
  structElement.fields.forEach(fieldKey => {
3362
3369
  this.setFieldVisibility(fieldKey, error, !!(field.value && structElement.showOnlyIfTrue));
@@ -3551,7 +3558,7 @@ class FormCore {
3551
3558
  set(values, val.nameToSubmit || key, val.value);
3552
3559
  }
3553
3560
  });
3554
- console.log(values);
3561
+ console.table(values);
3555
3562
  }
3556
3563
  /**
3557
3564
  * Gets the current values of all form fields.
@@ -3759,7 +3766,7 @@ class FormGroup {
3759
3766
  * Prints the form group instance to the console.
3760
3767
  */
3761
3768
  printFormGroupInstance() {
3762
- console.log(this.forms);
3769
+ console.table(this.forms);
3763
3770
  }
3764
3771
  /**
3765
3772
  * Prototype submit function to multiple forms
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "0.0.1-beta.26",
3
+ "version": "0.0.1-beta.28",
4
4
  "module": "./index.esm.js",
5
5
  "type": "module",
6
6
  "main": "./index.esm.js",
@@ -139,6 +139,14 @@ declare class FormCore {
139
139
  * @private
140
140
  */
141
141
  private static checkIndexes;
142
+ /**
143
+ * @internal
144
+ * Update field visibility accordingly.
145
+ *
146
+ * @param {string} field - Field name to be updated.
147
+ * @param {boolean} hasError - Condition to be used as visibility.
148
+ * @param {boolean|undefined} showOnlyIfTrue - Flag to be considered when update field visibility. If it's true, then considered error, if it's false, always considered the opposite.
149
+ */
142
150
  private setFieldVisibility;
143
151
  /**
144
152
  * Validates visibility conditions for a given event and updates field visibility accordingly.