@formio/js 5.1.0-rc.21 → 5.1.0-rc.23

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 (40) hide show
  1. package/dist/formio.embed.js +1 -1
  2. package/dist/formio.embed.min.js +1 -1
  3. package/dist/formio.embed.min.js.LICENSE.txt +1 -1
  4. package/dist/formio.form.js +54 -32
  5. package/dist/formio.form.min.js +1 -1
  6. package/dist/formio.form.min.js.LICENSE.txt +2 -2
  7. package/dist/formio.full.js +55 -33
  8. package/dist/formio.full.min.js +1 -1
  9. package/dist/formio.full.min.js.LICENSE.txt +2 -2
  10. package/dist/formio.js +3 -3
  11. package/dist/formio.min.js +1 -1
  12. package/dist/formio.min.js.LICENSE.txt +2 -2
  13. package/dist/formio.utils.js +1 -1
  14. package/dist/formio.utils.min.js +1 -1
  15. package/dist/formio.utils.min.js.LICENSE.txt +2 -2
  16. package/lib/cjs/Embed.js +1 -1
  17. package/lib/cjs/Formio.js +1 -1
  18. package/lib/cjs/WebformBuilder.js +1 -1
  19. package/lib/cjs/components/_classes/component/Component.d.ts +4 -15
  20. package/lib/cjs/components/_classes/component/Component.js +35 -57
  21. package/lib/cjs/components/_classes/nested/NestedComponent.js +3 -7
  22. package/lib/cjs/components/datamap/DataMap.js +2 -6
  23. package/lib/cjs/components/editgrid/EditGrid.js +0 -4
  24. package/lib/cjs/components/form/Form.js +7 -11
  25. package/lib/cjs/components/html/HTML.js +1 -2
  26. package/lib/cjs/components/radio/Radio.js +1 -1
  27. package/lib/cjs/components/tabs/Tabs.js +1 -0
  28. package/lib/mjs/Embed.js +1 -1
  29. package/lib/mjs/Formio.js +1 -1
  30. package/lib/mjs/WebformBuilder.js +1 -1
  31. package/lib/mjs/components/_classes/component/Component.d.ts +4 -15
  32. package/lib/mjs/components/_classes/component/Component.js +35 -57
  33. package/lib/mjs/components/_classes/nested/NestedComponent.js +3 -7
  34. package/lib/mjs/components/datamap/DataMap.js +2 -6
  35. package/lib/mjs/components/editgrid/EditGrid.js +0 -4
  36. package/lib/mjs/components/form/Form.js +7 -11
  37. package/lib/mjs/components/html/HTML.js +1 -2
  38. package/lib/mjs/components/radio/Radio.js +1 -1
  39. package/lib/mjs/components/tabs/Tabs.js +1 -0
  40. package/package.json +3 -3
@@ -315,18 +315,11 @@ export default class Component extends Element {
315
315
  this._path = '';
316
316
  // Needs for Nextgen Rules Engine
317
317
  this.resetCaches();
318
- /**
319
- * Determines if this component is conditionally hidden. Should generally not be set outside of conditional logic pipeline.
320
- * This is necessary because of clearOnHide behavior that only clears when conditionally hidden - we need to track
321
- * conditionallyHidden separately from "regular" visibility.
322
- */
323
- this._parentConditionallyHidden = this.options.hasOwnProperty('parentConditionallyHidden') ? this.options.parentConditionallyHidden : false;
324
- this._conditionallyHidden = this.checkConditionallyHidden(null, data) || this._parentConditionallyHidden;
325
318
  /**
326
319
  * Determines if this component is visible, or not.
327
320
  */
328
321
  this._parentVisible = this.options.hasOwnProperty('parentVisible') ? this.options.parentVisible : true;
329
- this._visible = this._parentVisible && (this.hasCondition() ? !this._conditionallyHidden : !this.component.hidden);
322
+ this._visible = this._parentVisible && (this.hasCondition() ? !this.conditionallyHidden() : !this.component.hidden);
330
323
  this._parentDisabled = false;
331
324
  /**
332
325
  * The reference attribute name for this component
@@ -395,7 +388,7 @@ export default class Component extends Element {
395
388
  if (this.allowData && this.key) {
396
389
  this.options.name += `[${this.key}]`;
397
390
  // If component is visible or not set to clear on hide, set the default value.
398
- if (!(this.conditionallyHidden && this.component.clearOnHide)) {
391
+ if (!(this.conditionallyHidden() && this.component.clearOnHide)) {
399
392
  if (!this.hasValue()) {
400
393
  if (this.shouldAddDefaultValue) {
401
394
  this.dataValue = this.defaultValue;
@@ -425,6 +418,16 @@ export default class Component extends Element {
425
418
  get componentsMap() {
426
419
  return this.root?.childComponentsMap || {};
427
420
  }
421
+ parentConditionallyHidden() {
422
+ let currentParent = this.parent;
423
+ while (currentParent) {
424
+ if (currentParent.conditionallyHidden(true)) {
425
+ return true;
426
+ }
427
+ currentParent = currentParent.parent;
428
+ }
429
+ return false;
430
+ }
428
431
  get data() {
429
432
  return this._data;
430
433
  }
@@ -464,8 +467,7 @@ export default class Component extends Element {
464
467
  }
465
468
  init() {
466
469
  this.disabled = this.shouldDisabled;
467
- this._conditionallyHidden = this.checkConditionallyHidden();
468
- this._visible = (this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden);
470
+ this._visible = (this.hasCondition() ? !this.conditionallyHidden() : !this.component.hidden);
469
471
  if (this.component.addons?.length) {
470
472
  this.component.addons.forEach((addon) => this.createAddon(addon));
471
473
  }
@@ -628,20 +630,17 @@ export default class Component extends Element {
628
630
  }
629
631
  return this._visible && this._parentVisible;
630
632
  }
631
- get conditionallyHidden() {
632
- return this._conditionallyHidden || this._parentConditionallyHidden;
633
+ get logicallyHidden() {
634
+ if (this._logicallyHidden && !this.component.hidden) {
635
+ this._logicallyHidden = false;
636
+ }
637
+ return this._logicallyHidden;
633
638
  }
634
- /**
635
- * Evaluates whether the component is conditionally hidden (as opposed to intentionally hidden, e.g. via the `hidden` component schema property).
636
- * @param {object} data - The data object to evaluate the condition against.
637
- * @param {object} row - The row object to evaluate the condition against.
638
- * @returns {boolean} - Whether the component is conditionally hidden.
639
- */
640
- checkConditionallyHidden(data = null, row = null) {
639
+ conditionallyHidden(skipParent = false) {
641
640
  if (!this.hasCondition()) {
642
- return false;
641
+ return this.logicallyHidden || (skipParent ? false : this.parentConditionallyHidden());
643
642
  }
644
- return !this.conditionallyVisible(data, row);
643
+ return !this.conditionallyVisible() || this.logicallyHidden || (skipParent ? false : this.parentConditionallyHidden());
645
644
  }
646
645
  get currentForm() {
647
646
  return this._currentForm;
@@ -1813,7 +1812,7 @@ export default class Component extends Element {
1813
1812
  rebuild() {
1814
1813
  this.destroy();
1815
1814
  this.init();
1816
- this.visible = this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden;
1815
+ this.visible = this.hasCondition() ? !this.conditionallyHidden() : !this.component.hidden;
1817
1816
  return this.redraw();
1818
1817
  }
1819
1818
  /**
@@ -1911,23 +1910,12 @@ export default class Component extends Element {
1911
1910
  if (!this.builderMode & !this.previewMode && this.fieldLogic(data, row)) {
1912
1911
  this.redraw();
1913
1912
  }
1914
- // Check advanced conditions (and cache the result)
1915
- const isConditionallyHidden = this.checkConditionallyHidden(data, row) || this._parentConditionallyHidden;
1916
- let shouldClear = false;
1917
- if (isConditionallyHidden !== this._conditionallyHidden) {
1918
- this._conditionallyHidden = isConditionallyHidden;
1919
- shouldClear = true;
1920
- }
1921
1913
  // Check visibility
1922
- const visible = (this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden);
1914
+ const visible = (this.hasCondition() ? !this.conditionallyHidden() : !this.component.hidden);
1923
1915
  if (this.visible !== visible) {
1924
1916
  this.visible = visible;
1925
1917
  }
1926
- // Wait for visibility to update for nested components, so the component state is up-to-date when
1927
- // calling clearOnHide
1928
- if (shouldClear) {
1929
- this.clearOnHide();
1930
- }
1918
+ this.clearOnHide();
1931
1919
  return visible;
1932
1920
  }
1933
1921
  /**
@@ -2036,9 +2024,9 @@ export default class Component extends Element {
2036
2024
  if (!_.isEqual(_.get(this.component, property), _.get(newComponent, property))) {
2037
2025
  // Advanced Logic can modify the component's hidden property; because we track conditionally hidden state
2038
2026
  // separately from the component's hidden property, and technically this Advanced Logic conditionally hides
2039
- // a component, we need to set _conditionallyHidden to the new value
2027
+ // a component, we need to set a temporary variable to the new value
2040
2028
  if (property === 'hidden') {
2041
- this._conditionallyHidden = newComponent.hidden;
2029
+ this._logicallyHidden = newComponent.hidden;
2042
2030
  }
2043
2031
  changed = true;
2044
2032
  }
@@ -2053,7 +2041,7 @@ export default class Component extends Element {
2053
2041
  component: newComponent,
2054
2042
  result,
2055
2043
  });
2056
- if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden)) {
2044
+ if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden())) {
2057
2045
  this.setValue(newValue);
2058
2046
  if (this.viewOnly) {
2059
2047
  this.dataValue = newValue;
@@ -2086,7 +2074,7 @@ export default class Component extends Element {
2086
2074
  component: newComponent,
2087
2075
  result,
2088
2076
  }, 'value');
2089
- if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden)) {
2077
+ if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden())) {
2090
2078
  this.setValue(newValue);
2091
2079
  if (this.viewOnly) {
2092
2080
  this.dataValue = newValue;
@@ -2197,7 +2185,7 @@ export default class Component extends Element {
2197
2185
  this.component.clearOnHide !== false &&
2198
2186
  !this.options.readOnly &&
2199
2187
  !this.options.showHiddenFields) {
2200
- if (this.conditionallyHidden) {
2188
+ if (this.conditionallyHidden()) {
2201
2189
  this.deleteValue();
2202
2190
  }
2203
2191
  else if (!this.hasValue() && this.shouldAddDefaultValue) {
@@ -2451,27 +2439,17 @@ export default class Component extends Element {
2451
2439
  * @returns {*} - The value for this component.
2452
2440
  */
2453
2441
  get dataValue() {
2454
- if (!this.key ||
2455
- (this.conditionallyHidden && this.component.clearOnHide && !this.rootPristine)) {
2456
- return this.emptyValue;
2457
- }
2458
- if (!this.hasValue() && this.shouldAddDefaultValue) {
2459
- const empty = this.component.multiple ? [] : this.emptyValue;
2460
- if (!this.rootPristine) {
2461
- this.dataValue = empty;
2462
- }
2463
- return empty;
2442
+ if (!this.key) {
2443
+ return this.component.multiple ? [] : this.emptyValue;
2464
2444
  }
2465
- return _.get(this._data, this.key);
2445
+ return _.get(this._data, this.key, this.component.multiple ? [] : this.emptyValue);
2466
2446
  }
2467
2447
  /**
2468
2448
  * Sets the static value of this component.
2469
2449
  * @param {*} value - The value to set for this component.
2470
2450
  */
2471
2451
  set dataValue(value) {
2472
- if (!this.allowData ||
2473
- !this.key ||
2474
- (this.conditionallyHidden && this.component.clearOnHide && !this.rootPristine)) {
2452
+ if (!this.allowData || !this.key) {
2475
2453
  return;
2476
2454
  }
2477
2455
  if ((value !== null) && (value !== undefined)) {
@@ -2791,7 +2769,7 @@ export default class Component extends Element {
2791
2769
  // If no calculated value or
2792
2770
  // hidden and set to clearOnHide (Don't calculate a value for a hidden field set to clear when hidden)
2793
2771
  const { clearOnHide } = this.component;
2794
- const shouldBeCleared = this.conditionallyHidden && clearOnHide;
2772
+ const shouldBeCleared = this.conditionallyHidden() && clearOnHide;
2795
2773
  const allowOverride = _.get(this.component, 'allowCalculateOverride', false);
2796
2774
  if (shouldBeCleared) {
2797
2775
  // remove calculated value so that the value is recalculated once component becomes visible
@@ -3436,7 +3414,7 @@ export default class Component extends Element {
3436
3414
  // If component definition changed, replace it.
3437
3415
  if (!_.isEqual(this.component, newComponent)) {
3438
3416
  this.component = newComponent;
3439
- const visible = this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden;
3417
+ const visible = this.hasCondition() ? !this.conditionallyHidden() : !this.component.hidden;
3440
3418
  const disabled = this.shouldDisabled;
3441
3419
  // Change states which won't be recalculated during redrawing
3442
3420
  if (this.visible !== visible) {
@@ -81,18 +81,15 @@ export default class NestedComponent extends Field {
81
81
  const visibilityChanged = this._visible !== value;
82
82
  this._visible = value;
83
83
  const isVisible = this.visible;
84
- const isConditionallyHidden = this.checkConditionallyHidden();
85
84
  const forceShow = this.shouldForceShow();
86
85
  const forceHide = this.shouldForceHide();
87
86
  this.components.forEach((component) => {
88
87
  // Set the parent visibility first since we may have nested components within nested components
89
88
  // and they need to be able to determine their visibility based on the parent visibility.
90
89
  component.parentVisible = isVisible;
91
- component._parentConditionallyHidden = isConditionallyHidden;
92
90
  let visible;
93
91
  if (component.hasCondition()) {
94
- component._conditionallyHidden = component.checkConditionallyHidden() || component._parentConditionallyHidden;
95
- visible = !component.conditionallyHidden;
92
+ visible = !component.conditionallyHidden();
96
93
  }
97
94
  else {
98
95
  visible = !component.component.hidden;
@@ -373,7 +370,6 @@ export default class NestedComponent extends Field {
373
370
  data = data || this.data;
374
371
  options.parent = this;
375
372
  options.parentVisible = this.visible;
376
- options.parentConditionallyHidden = this.conditionallyHidden;
377
373
  options.root = options?.root || this.root || this;
378
374
  options.localRoot = this.localRoot;
379
375
  options.skipInit = true;
@@ -632,7 +628,7 @@ export default class NestedComponent extends Field {
632
628
  clearOnHide(show) {
633
629
  super.clearOnHide(show);
634
630
  if (this.component.clearOnHide) {
635
- if (this.allowData && !this.hasValue() && !this.conditionallyHidden) {
631
+ if (this.allowData && !this.hasValue() && !this.conditionallyHidden()) {
636
632
  this.dataValue = this.defaultValue;
637
633
  }
638
634
  if (this.hasValue()) {
@@ -661,7 +657,7 @@ export default class NestedComponent extends Field {
661
657
  }
662
658
  calculateValue(data, flags, row) {
663
659
  // Do not iterate into children and calculateValues if this nested component is conditionally hidden.
664
- if (this.conditionallyHidden) {
660
+ if (this.conditionallyHidden()) {
665
661
  return false;
666
662
  }
667
663
  return this.getComponents().reduce((changed, comp) => comp.calculateValue(data, flags, row) || changed, super.calculateValue(data, flags, row));
@@ -68,14 +68,10 @@ export default class DataMapComponent extends DataGridComponent {
68
68
  return {};
69
69
  }
70
70
  get dataValue() {
71
- if (!this.key ||
72
- (this.conditionallyHidden && this.component.clearOnHide)) {
71
+ if (!this.key) {
73
72
  return this.emptyValue;
74
73
  }
75
- if (!this.hasValue() && this.shouldAddDefaultValue) {
76
- this.dataValue = this.emptyValue;
77
- }
78
- return _.get(this.data, this.key);
74
+ return _.get(this.data, this.key, this.emptyValue);
79
75
  }
80
76
  set dataValue(value) {
81
77
  super.dataValue = value;
@@ -1132,9 +1132,6 @@ export default class EditGridComponent extends NestedArrayComponent {
1132
1132
  }
1133
1133
  }
1134
1134
  const changed = this.hasChanged(value, this.dataValue);
1135
- if (this.parent) {
1136
- this.parent.checkComponentConditions();
1137
- }
1138
1135
  this.dataValue = value;
1139
1136
  // Refresh editRow data when data changes.
1140
1137
  this.dataValue.forEach((row, rowIndex) => {
@@ -1165,7 +1162,6 @@ export default class EditGridComponent extends NestedArrayComponent {
1165
1162
  this.editRows = this.editRows.slice(0, dataLength);
1166
1163
  this.openWhenEmpty();
1167
1164
  this.updateOnChange(flags, changed);
1168
- this.checkData();
1169
1165
  this.changeState(changed, flags);
1170
1166
  return changed;
1171
1167
  }
@@ -441,7 +441,7 @@ export default class FormComponent extends Component {
441
441
  */
442
442
  loadSubForm(fromAttach, beforeSubmit) {
443
443
  const loadHiddenForm = beforeSubmit && !this.component.clearOnHide;
444
- if (this.builderMode || (this.conditionallyHidden && !loadHiddenForm) || (this.isSubFormLazyLoad() && !fromAttach)) {
444
+ if (this.builderMode || (this.conditionallyHidden() && !loadHiddenForm) || (this.isSubFormLazyLoad() && !fromAttach)) {
445
445
  return Promise.resolve();
446
446
  }
447
447
  if (this.hasLoadedForm && !this.isRevisionChanged &&
@@ -513,7 +513,7 @@ export default class FormComponent extends Component {
513
513
  * @returns {*|boolean} - TRUE if the subform should be submitted, FALSE if it should not.
514
514
  */
515
515
  get shouldSubmit() {
516
- return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && (!this.conditionallyHidden || !this.component.clearOnHide);
516
+ return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && (!this.conditionallyHidden() || !this.component.clearOnHide);
517
517
  }
518
518
  /**
519
519
  * Returns the data for the subform.
@@ -584,20 +584,16 @@ export default class FormComponent extends Component {
584
584
  return Promise.resolve(this.dataValue);
585
585
  }
586
586
  // we need to load a hidden form (when clearOnHide is disabled) in order to get and submit (if needed) its data
587
- const loadHiddenForm = !this.subForm && !this.component.clearOnHide;
588
- if ((this.isSubFormLazyLoad() || loadHiddenForm) && !this.subFormLoading) {
587
+ const loadHiddenForm = !this.component.clearOnHide;
588
+ if ((this.isSubFormLazyLoad() || loadHiddenForm) && !this.subFormLoading && !this.subForm) {
589
589
  return this.createSubForm(true, true)
590
- .then(this.submitSubForm(false))
591
- .then(() => {
592
- return this.dataValue;
593
- })
590
+ .then(() => this.submitSubForm(false))
591
+ .then(() => this.dataValue)
594
592
  .then(() => super.beforeSubmit());
595
593
  }
596
594
  else {
597
595
  return this.submitSubForm(false)
598
- .then(() => {
599
- return this.dataValue;
600
- })
596
+ .then(() => this.dataValue)
601
597
  .then(() => super.beforeSubmit());
602
598
  }
603
599
  }
@@ -53,8 +53,7 @@ export default class HTMLComponent extends Component {
53
53
  super.checkRefreshOn(changed);
54
54
  let visible;
55
55
  if (this.hasCondition()) {
56
- this._conditionallyHidden = this.checkConditionallyHidden();
57
- visible = !this.conditionallyHidden;
56
+ visible = !this.conditionallyHidden();
58
57
  }
59
58
  else {
60
59
  visible = !this.component.hidden;
@@ -355,7 +355,7 @@ export default class RadioComponent extends ListComponent {
355
355
  const value = this.dataValue;
356
356
  this.refs.wrapper.forEach((wrapper, index) => {
357
357
  const input = this.refs.input[index];
358
- const checked = (input.type === 'checkbox') ? value[input.value] || input.checked : (input.value.toString() === value.toString());
358
+ const checked = (value === undefined || value === null) ? false : (input.type === 'checkbox') ? value[input.value] || input.checked : (input.value.toString() === value.toString());
359
359
  if (checked) {
360
360
  //add class to container when selected
361
361
  this.addClass(wrapper, this.optionSelectedClass);
@@ -138,6 +138,7 @@ export default class TabsComponent extends NestedComponent {
138
138
  this.addClass(this.refs[this.tabLinkKey][index], 'active');
139
139
  this.addClass(this.refs[this.tabLinkKey][index], 'formio-tab-link-active');
140
140
  }
141
+ this.setValue(this.data);
141
142
  this.triggerChange();
142
143
  }
143
144
  beforeFocus(component) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-rc.21",
3
+ "version": "5.1.0-rc.23",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {
@@ -79,9 +79,9 @@
79
79
  },
80
80
  "homepage": "https://github.com/formio/formio.js#readme",
81
81
  "dependencies": {
82
- "@formio/bootstrap": "3.1.0-rc.2",
82
+ "@formio/bootstrap": "3.1.0-rc.3",
83
83
  "@formio/choices.js": "^10.2.1",
84
- "@formio/core": "2.4.0-rc.11",
84
+ "@formio/core": "2.4.0-rc.12",
85
85
  "@formio/text-mask-addons": "^3.8.0-formio.4",
86
86
  "@formio/vanilla-text-mask": "^5.1.1-formio.1",
87
87
  "abortcontroller-polyfill": "^1.7.5",