@formio/js 5.1.0-rc.1 → 5.1.0-rc.3

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 (32) 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 +19 -19
  5. package/dist/formio.form.min.js +1 -1
  6. package/dist/formio.form.min.js.LICENSE.txt +1 -1
  7. package/dist/formio.full.js +19 -19
  8. package/dist/formio.full.min.js +1 -1
  9. package/dist/formio.full.min.js.LICENSE.txt +1 -1
  10. package/dist/formio.js +12 -12
  11. package/dist/formio.min.js +1 -1
  12. package/dist/formio.min.js.LICENSE.txt +1 -1
  13. package/dist/formio.utils.js +10 -10
  14. package/dist/formio.utils.min.js +1 -1
  15. package/dist/formio.utils.min.js.LICENSE.txt +1 -1
  16. package/lib/cjs/components/_classes/component/Component.d.ts +15 -0
  17. package/lib/cjs/components/_classes/component/Component.js +50 -16
  18. package/lib/cjs/components/_classes/component/editForm/Component.edit.data.js +2 -2
  19. package/lib/cjs/components/_classes/nested/NestedComponent.js +16 -7
  20. package/lib/cjs/components/datamap/DataMap.js +1 -1
  21. package/lib/cjs/components/editgrid/EditGrid.js +2 -5
  22. package/lib/cjs/components/form/Form.js +5 -4
  23. package/lib/cjs/components/html/HTML.js +15 -3
  24. package/lib/mjs/components/_classes/component/Component.d.ts +15 -0
  25. package/lib/mjs/components/_classes/component/Component.js +50 -16
  26. package/lib/mjs/components/_classes/component/editForm/Component.edit.data.js +2 -2
  27. package/lib/mjs/components/_classes/nested/NestedComponent.js +16 -7
  28. package/lib/mjs/components/datamap/DataMap.js +1 -1
  29. package/lib/mjs/components/editgrid/EditGrid.js +2 -5
  30. package/lib/mjs/components/form/Form.js +5 -4
  31. package/lib/mjs/components/html/HTML.js +15 -3
  32. package/package.json +2 -2
@@ -20,7 +20,7 @@
20
20
 
21
21
  /*! @license DOMPurify 3.2.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.3/LICENSE */
22
22
 
23
- /*! formiojs v5.1.0-rc.1 | https://unpkg.com/formiojs@5.1.0-rc.1/LICENSE.txt */
23
+ /*! formiojs v5.1.0-rc.3 | https://unpkg.com/formiojs@5.1.0-rc.3/LICENSE.txt */
24
24
 
25
25
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
26
26
 
@@ -119,6 +119,13 @@ declare class Component extends Element {
119
119
  */
120
120
  paths: import('@formio/core').ComponentPaths;
121
121
  _path: string;
122
+ /**
123
+ * Determines if this component is conditionally hidden. Should generally not be set outside of conditional logic pipeline.
124
+ * This is necessary because of clearOnHide behavior that only clears when conditionally hidden - we need to track
125
+ * conditionallyHidden separately from "regular" visibility.
126
+ */
127
+ _parentConditionallyHidden: any;
128
+ _conditionallyHidden: any;
122
129
  /**
123
130
  * Determines if this component is visible, or not.
124
131
  */
@@ -224,6 +231,14 @@ declare class Component extends Element {
224
231
  * @returns {boolean} - Whether the component is visible or not.
225
232
  */
226
233
  get visible(): boolean;
234
+ get conditionallyHidden(): any;
235
+ /**
236
+ * Evaluates whether the component is conditionally hidden (as opposed to intentionally hidden, e.g. via the `hidden` component schema property).
237
+ * @param {object} data - The data object to evaluate the condition against.
238
+ * @param {object} row - The row object to evaluate the condition against.
239
+ * @returns {boolean} - Whether the component is conditionally hidden.
240
+ */
241
+ checkConditionallyHidden(data?: object, row?: object): boolean;
227
242
  set currentForm(instance: any);
228
243
  get currentForm(): any;
229
244
  _currentForm: any;
@@ -341,11 +341,18 @@ class Component extends Element_1.default {
341
341
  this._path = '';
342
342
  // Needs for Nextgen Rules Engine
343
343
  this.resetCaches();
344
+ /**
345
+ * Determines if this component is conditionally hidden. Should generally not be set outside of conditional logic pipeline.
346
+ * This is necessary because of clearOnHide behavior that only clears when conditionally hidden - we need to track
347
+ * conditionallyHidden separately from "regular" visibility.
348
+ */
349
+ this._parentConditionallyHidden = this.options.hasOwnProperty('parentConditionallyHidden') ? this.options.parentConditionallyHidden : false;
350
+ this._conditionallyHidden = this.checkConditionallyHidden(null, data) || this._parentConditionallyHidden;
344
351
  /**
345
352
  * Determines if this component is visible, or not.
346
353
  */
347
354
  this._parentVisible = this.options.hasOwnProperty('parentVisible') ? this.options.parentVisible : true;
348
- this._visible = this._parentVisible && this.conditionallyVisible(null, data);
355
+ this._visible = this._parentVisible && (this.hasCondition() ? !this._conditionallyHidden : !this.component.hidden);
349
356
  this._parentDisabled = false;
350
357
  /**
351
358
  * The reference attribute name for this component
@@ -414,7 +421,7 @@ class Component extends Element_1.default {
414
421
  if (this.allowData && this.key) {
415
422
  this.options.name += `[${this.key}]`;
416
423
  // If component is visible or not set to clear on hide, set the default value.
417
- if (this.visible || !this.component.clearOnHide) {
424
+ if (!(this.conditionallyHidden && this.component.clearOnHide)) {
418
425
  if (!this.hasValue()) {
419
426
  if (this.shouldAddDefaultValue) {
420
427
  this.dataValue = this.defaultValue;
@@ -485,7 +492,8 @@ class Component extends Element_1.default {
485
492
  init() {
486
493
  var _a;
487
494
  this.disabled = this.shouldDisabled;
488
- this._visible = this.conditionallyVisible(null, null);
495
+ this._conditionallyHidden = this.checkConditionallyHidden();
496
+ this._visible = (this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden);
489
497
  if ((_a = this.component.addons) === null || _a === void 0 ? void 0 : _a.length) {
490
498
  this.component.addons.forEach((addon) => this.createAddon(addon));
491
499
  }
@@ -627,7 +635,6 @@ class Component extends Element_1.default {
627
635
  return;
628
636
  }
629
637
  this._visible = value;
630
- this.clearOnHide();
631
638
  this.redraw();
632
639
  }
633
640
  }
@@ -648,6 +655,21 @@ class Component extends Element_1.default {
648
655
  }
649
656
  return this._visible && this._parentVisible;
650
657
  }
658
+ get conditionallyHidden() {
659
+ return this._conditionallyHidden || this._parentConditionallyHidden;
660
+ }
661
+ /**
662
+ * Evaluates whether the component is conditionally hidden (as opposed to intentionally hidden, e.g. via the `hidden` component schema property).
663
+ * @param {object} data - The data object to evaluate the condition against.
664
+ * @param {object} row - The row object to evaluate the condition against.
665
+ * @returns {boolean} - Whether the component is conditionally hidden.
666
+ */
667
+ checkConditionallyHidden(data = null, row = null) {
668
+ if (!this.hasCondition()) {
669
+ return false;
670
+ }
671
+ return !this.conditionallyVisible(data, row);
672
+ }
651
673
  get currentForm() {
652
674
  return this._currentForm;
653
675
  }
@@ -1816,7 +1838,7 @@ class Component extends Element_1.default {
1816
1838
  rebuild() {
1817
1839
  this.destroy();
1818
1840
  this.init();
1819
- this.visible = this.conditionallyVisible(null, null);
1841
+ this.visible = this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden;
1820
1842
  return this.redraw();
1821
1843
  }
1822
1844
  /**
@@ -1883,8 +1905,8 @@ class Component extends Element_1.default {
1883
1905
  conditionallyVisible(data, row) {
1884
1906
  data = data || this.rootValue;
1885
1907
  row = row || this.data;
1886
- if (this.builderMode || this.previewMode || !this.hasCondition()) {
1887
- return !this.component.hidden;
1908
+ if (this.builderMode || this.previewMode) {
1909
+ return true;
1888
1910
  }
1889
1911
  data = data || (this.root ? this.root.data : {});
1890
1912
  return this.checkCondition(row, data);
@@ -1914,8 +1936,14 @@ class Component extends Element_1.default {
1914
1936
  if (!this.builderMode & !this.previewMode && this.fieldLogic(data, row)) {
1915
1937
  this.redraw();
1916
1938
  }
1917
- // Check advanced conditions
1918
- const visible = this.conditionallyVisible(data, row);
1939
+ // Check advanced conditions (and cache the result)
1940
+ const isConditionallyHidden = this.checkConditionallyHidden(data, row) || this._parentConditionallyHidden;
1941
+ if (isConditionallyHidden !== this._conditionallyHidden) {
1942
+ this._conditionallyHidden = isConditionallyHidden;
1943
+ this.clearOnHide();
1944
+ }
1945
+ // Check visibility
1946
+ const visible = (this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden);
1919
1947
  if (this.visible !== visible) {
1920
1948
  this.visible = visible;
1921
1949
  }
@@ -2025,6 +2053,12 @@ class Component extends Element_1.default {
2025
2053
  FormioUtils.setActionProperty(newComponent, action, result, row, data, this);
2026
2054
  const property = action.property.value;
2027
2055
  if (!lodash_1.default.isEqual(lodash_1.default.get(this.component, property), lodash_1.default.get(newComponent, property))) {
2056
+ // Advanced Logic can modify the component's hidden property; because we track conditionally hidden state
2057
+ // separately from the component's hidden property, and technically this Advanced Logic conditionally hides
2058
+ // a component, we need to set _conditionallyHidden to the new value
2059
+ if (property === 'hidden') {
2060
+ this._conditionallyHidden = newComponent.hidden;
2061
+ }
2028
2062
  changed = true;
2029
2063
  }
2030
2064
  break;
@@ -2038,7 +2072,7 @@ class Component extends Element_1.default {
2038
2072
  component: newComponent,
2039
2073
  result,
2040
2074
  });
2041
- if (!lodash_1.default.isEqual(oldValue, newValue) && !(this.component.clearOnHide && !this.visible)) {
2075
+ if (!lodash_1.default.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden)) {
2042
2076
  this.setValue(newValue);
2043
2077
  if (this.viewOnly) {
2044
2078
  this.dataValue = newValue;
@@ -2071,7 +2105,7 @@ class Component extends Element_1.default {
2071
2105
  component: newComponent,
2072
2106
  result,
2073
2107
  }, 'value');
2074
- if (!lodash_1.default.isEqual(oldValue, newValue) && !(this.component.clearOnHide && !this.visible)) {
2108
+ if (!lodash_1.default.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden)) {
2075
2109
  this.setValue(newValue);
2076
2110
  if (this.viewOnly) {
2077
2111
  this.dataValue = newValue;
@@ -2182,7 +2216,7 @@ class Component extends Element_1.default {
2182
2216
  this.component.clearOnHide !== false &&
2183
2217
  !this.options.readOnly &&
2184
2218
  !this.options.showHiddenFields) {
2185
- if (!this.visible) {
2219
+ if (this.conditionallyHidden) {
2186
2220
  this.deleteValue();
2187
2221
  }
2188
2222
  else if (!this.hasValue() && this.shouldAddDefaultValue) {
@@ -2432,7 +2466,7 @@ class Component extends Element_1.default {
2432
2466
  */
2433
2467
  get dataValue() {
2434
2468
  if (!this.key ||
2435
- (!this.visible && this.component.clearOnHide && !this.rootPristine)) {
2469
+ (this.conditionallyHidden && this.component.clearOnHide && !this.rootPristine)) {
2436
2470
  return this.emptyValue;
2437
2471
  }
2438
2472
  if (!this.hasValue() && this.shouldAddDefaultValue) {
@@ -2451,7 +2485,7 @@ class Component extends Element_1.default {
2451
2485
  set dataValue(value) {
2452
2486
  if (!this.allowData ||
2453
2487
  !this.key ||
2454
- (!this.visible && this.component.clearOnHide && !this.rootPristine)) {
2488
+ (this.conditionallyHidden && this.component.clearOnHide && !this.rootPristine)) {
2455
2489
  return;
2456
2490
  }
2457
2491
  if ((value !== null) && (value !== undefined)) {
@@ -2772,7 +2806,7 @@ class Component extends Element_1.default {
2772
2806
  // If no calculated value or
2773
2807
  // hidden and set to clearOnHide (Don't calculate a value for a hidden field set to clear when hidden)
2774
2808
  const { clearOnHide } = this.component;
2775
- const shouldBeCleared = !this.visible && clearOnHide;
2809
+ const shouldBeCleared = this.conditionallyHidden && clearOnHide;
2776
2810
  const allowOverride = lodash_1.default.get(this.component, 'allowCalculateOverride', false);
2777
2811
  if (shouldBeCleared) {
2778
2812
  // remove calculated value so that the value is recalculated once component becomes visible
@@ -3422,7 +3456,7 @@ class Component extends Element_1.default {
3422
3456
  // If component definition changed, replace it.
3423
3457
  if (!lodash_1.default.isEqual(this.component, newComponent)) {
3424
3458
  this.component = newComponent;
3425
- const visible = this.conditionallyVisible(null, null);
3459
+ const visible = this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden;
3426
3460
  const disabled = this.shouldDisabled;
3427
3461
  // Change states which won't be recalculated during redrawing
3428
3462
  if (this.visible !== visible) {
@@ -133,10 +133,10 @@ exports.default = [
133
133
  {
134
134
  weight: 700,
135
135
  type: 'checkbox',
136
- label: 'Clear Value When Hidden',
136
+ label: 'Omit Value From Submission Data When Conditionally Hidden',
137
137
  key: 'clearOnHide',
138
138
  defaultValue: true,
139
- tooltip: 'When a field is hidden, clear the value.',
139
+ tooltip: 'When a field is conditionally hidden, omit the value from the submission data.',
140
140
  input: true
141
141
  },
142
142
  utils_1.default.javaScriptValue('Custom Default Value', 'customDefaultValue', 'customDefaultValue', 1000, '<p><h4>Example:</h4><pre>value = data.firstName + " " + data.lastName;</pre></p>', '<p><h4>Example:</h4><pre>{"cat": [{"var": "data.firstName"}, " ", {"var": "data.lastName"}]}</pre>'),
@@ -85,17 +85,26 @@ class NestedComponent extends Field_1.default {
85
85
  const visibilityChanged = this._visible !== value;
86
86
  this._visible = value;
87
87
  const isVisible = this.visible;
88
+ const isConditionallyHidden = this.checkConditionallyHidden();
88
89
  const forceShow = this.shouldForceShow();
89
90
  const forceHide = this.shouldForceHide();
90
- this.components.forEach(component => {
91
+ this.components.forEach((component) => {
91
92
  // Set the parent visibility first since we may have nested components within nested components
92
93
  // and they need to be able to determine their visibility based on the parent visibility.
93
94
  component.parentVisible = isVisible;
94
- const conditionallyVisible = component.conditionallyVisible();
95
- if (forceShow || conditionallyVisible) {
95
+ component._parentConditionallyHidden = isConditionallyHidden;
96
+ let visible;
97
+ if (component.hasCondition()) {
98
+ component._conditionallyHidden = component.checkConditionallyHidden() || component._parentConditionallyHidden;
99
+ visible = !component.conditionallyHidden;
100
+ }
101
+ else {
102
+ visible = !component.component.hidden;
103
+ }
104
+ if (forceShow || visible) {
96
105
  component.visible = true;
97
106
  }
98
- else if (forceHide || !isVisible || !conditionallyVisible) {
107
+ else if (forceHide || !isVisible || !visible) {
99
108
  component.visible = false;
100
109
  }
101
110
  // If hiding a nested component, clear all errors below.
@@ -104,7 +113,6 @@ class NestedComponent extends Field_1.default {
104
113
  }
105
114
  });
106
115
  if (visibilityChanged) {
107
- this.clearOnHide();
108
116
  this.redraw();
109
117
  }
110
118
  }
@@ -369,6 +377,7 @@ class NestedComponent extends Field_1.default {
369
377
  data = data || this.data;
370
378
  options.parent = this;
371
379
  options.parentVisible = this.visible;
380
+ options.parentConditionallyHidden = this.conditionallyHidden;
372
381
  options.root = (options === null || options === void 0 ? void 0 : options.root) || this.root || this;
373
382
  options.localRoot = this.localRoot;
374
383
  options.skipInit = true;
@@ -627,7 +636,7 @@ class NestedComponent extends Field_1.default {
627
636
  clearOnHide(show) {
628
637
  super.clearOnHide(show);
629
638
  if (this.component.clearOnHide) {
630
- if (this.allowData && !this.hasValue() && !(this.options.server && !this.visible)) {
639
+ if (this.allowData && !this.hasValue() && !this.conditionallyHidden) {
631
640
  this.dataValue = this.defaultValue;
632
641
  }
633
642
  if (this.hasValue()) {
@@ -656,7 +665,7 @@ class NestedComponent extends Field_1.default {
656
665
  }
657
666
  calculateValue(data, flags, row) {
658
667
  // Do not iterate into children and calculateValues if this nested component is conditionally hidden.
659
- if (!this.conditionallyVisible()) {
668
+ if (this.conditionallyHidden) {
660
669
  return false;
661
670
  }
662
671
  return this.getComponents().reduce((changed, comp) => comp.calculateValue(data, flags, row) || changed, super.calculateValue(data, flags, row));
@@ -74,7 +74,7 @@ class DataMapComponent extends DataGrid_1.default {
74
74
  }
75
75
  get dataValue() {
76
76
  if (!this.key ||
77
- (!this.visible && this.component.clearOnHide)) {
77
+ (this.conditionallyHidden && this.component.clearOnHide)) {
78
78
  return this.emptyValue;
79
79
  }
80
80
  if (!this.hasValue() && this.shouldAddDefaultValue) {
@@ -1141,7 +1141,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
1141
1141
  }
1142
1142
  }
1143
1143
  const changed = this.hasChanged(value, this.dataValue);
1144
- if (this.parent && !this.options.server) {
1144
+ if (this.parent) {
1145
1145
  this.parent.checkComponentConditions();
1146
1146
  }
1147
1147
  this.dataValue = value;
@@ -1174,10 +1174,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
1174
1174
  this.editRows = this.editRows.slice(0, dataLength);
1175
1175
  this.openWhenEmpty();
1176
1176
  this.updateOnChange(flags, changed);
1177
- // do not call checkData with server option, it is called when change is triggered in updateOnChange
1178
- if (!this.options.server) {
1179
- this.checkData();
1180
- }
1177
+ this.checkData();
1181
1178
  this.changeState(changed, flags);
1182
1179
  return changed;
1183
1180
  }
@@ -425,10 +425,11 @@ class FormComponent extends Component_1.default {
425
425
  return this.subFormReady;
426
426
  }
427
427
  hideSubmitButton(component) {
428
- const isSubmitButton = (component.type === 'button') &&
429
- ((component.action === 'submit') || !component.action);
428
+ const isSubmitButton = component.type === 'button' && (component.action === 'submit' || !component.action);
430
429
  if (isSubmitButton) {
431
430
  component.hidden = true;
431
+ // clearOnHide no longer clears from the JSON `hidden` flag, so we make the button conditionally hidden to clear its data
432
+ component.customConditional = 'show = false';
432
433
  }
433
434
  }
434
435
  /**
@@ -438,7 +439,7 @@ class FormComponent extends Component_1.default {
438
439
  */
439
440
  loadSubForm(fromAttach) {
440
441
  var _a, _b, _c, _d, _e;
441
- if (this.builderMode || this.isHidden() || (this.isSubFormLazyLoad() && !fromAttach)) {
442
+ if (this.builderMode || this.conditionallyHidden || (this.isSubFormLazyLoad() && !fromAttach)) {
442
443
  return Promise.resolve();
443
444
  }
444
445
  if (this.hasLoadedForm && !this.isRevisionChanged &&
@@ -510,7 +511,7 @@ class FormComponent extends Component_1.default {
510
511
  * @returns {*|boolean} - TRUE if the subform should be submitted, FALSE if it should not.
511
512
  */
512
513
  get shouldSubmit() {
513
- return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && !this.isHidden();
514
+ return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && !this.conditionallyHidden;
514
515
  }
515
516
  /**
516
517
  * Returns the data for the subform.
@@ -56,9 +56,21 @@ class HTMLComponent extends Component_1.default {
56
56
  }
57
57
  checkRefreshOn(changed) {
58
58
  super.checkRefreshOn(changed);
59
- if (!this.builderMode && this.component.refreshOnChange && this.element &&
60
- !lodash_1.default.isUndefined(changed) && ((lodash_1.default.isBoolean(changed) && changed) || !lodash_1.default.isEmpty(changed)) &&
61
- this.conditionallyVisible(this.data, this.row)) {
59
+ let visible;
60
+ if (this.hasCondition()) {
61
+ this._conditionallyHidden = this.checkConditionallyHidden();
62
+ visible = !this.conditionallyHidden;
63
+ }
64
+ else {
65
+ visible = !this.component.hidden;
66
+ }
67
+ const shouldSetContent = !this.builderMode
68
+ && this.component.refreshOnChange
69
+ && this.element
70
+ && !lodash_1.default.isUndefined(changed)
71
+ && ((lodash_1.default.isBoolean(changed) && changed) || !lodash_1.default.isEmpty(changed))
72
+ && visible;
73
+ if (shouldSetContent) {
62
74
  this.setContent(this.element, this.renderContent());
63
75
  }
64
76
  }
@@ -119,6 +119,13 @@ declare class Component extends Element {
119
119
  */
120
120
  paths: import('@formio/core').ComponentPaths;
121
121
  _path: string;
122
+ /**
123
+ * Determines if this component is conditionally hidden. Should generally not be set outside of conditional logic pipeline.
124
+ * This is necessary because of clearOnHide behavior that only clears when conditionally hidden - we need to track
125
+ * conditionallyHidden separately from "regular" visibility.
126
+ */
127
+ _parentConditionallyHidden: any;
128
+ _conditionallyHidden: any;
122
129
  /**
123
130
  * Determines if this component is visible, or not.
124
131
  */
@@ -224,6 +231,14 @@ declare class Component extends Element {
224
231
  * @returns {boolean} - Whether the component is visible or not.
225
232
  */
226
233
  get visible(): boolean;
234
+ get conditionallyHidden(): any;
235
+ /**
236
+ * Evaluates whether the component is conditionally hidden (as opposed to intentionally hidden, e.g. via the `hidden` component schema property).
237
+ * @param {object} data - The data object to evaluate the condition against.
238
+ * @param {object} row - The row object to evaluate the condition against.
239
+ * @returns {boolean} - Whether the component is conditionally hidden.
240
+ */
241
+ checkConditionallyHidden(data?: object, row?: object): boolean;
227
242
  set currentForm(instance: any);
228
243
  get currentForm(): any;
229
244
  _currentForm: any;
@@ -315,11 +315,18 @@ 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;
318
325
  /**
319
326
  * Determines if this component is visible, or not.
320
327
  */
321
328
  this._parentVisible = this.options.hasOwnProperty('parentVisible') ? this.options.parentVisible : true;
322
- this._visible = this._parentVisible && this.conditionallyVisible(null, data);
329
+ this._visible = this._parentVisible && (this.hasCondition() ? !this._conditionallyHidden : !this.component.hidden);
323
330
  this._parentDisabled = false;
324
331
  /**
325
332
  * The reference attribute name for this component
@@ -388,7 +395,7 @@ export default class Component extends Element {
388
395
  if (this.allowData && this.key) {
389
396
  this.options.name += `[${this.key}]`;
390
397
  // If component is visible or not set to clear on hide, set the default value.
391
- if (this.visible || !this.component.clearOnHide) {
398
+ if (!(this.conditionallyHidden && this.component.clearOnHide)) {
392
399
  if (!this.hasValue()) {
393
400
  if (this.shouldAddDefaultValue) {
394
401
  this.dataValue = this.defaultValue;
@@ -457,7 +464,8 @@ export default class Component extends Element {
457
464
  }
458
465
  init() {
459
466
  this.disabled = this.shouldDisabled;
460
- this._visible = this.conditionallyVisible(null, null);
467
+ this._conditionallyHidden = this.checkConditionallyHidden();
468
+ this._visible = (this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden);
461
469
  if (this.component.addons?.length) {
462
470
  this.component.addons.forEach((addon) => this.createAddon(addon));
463
471
  }
@@ -600,7 +608,6 @@ export default class Component extends Element {
600
608
  return;
601
609
  }
602
610
  this._visible = value;
603
- this.clearOnHide();
604
611
  this.redraw();
605
612
  }
606
613
  }
@@ -621,6 +628,21 @@ export default class Component extends Element {
621
628
  }
622
629
  return this._visible && this._parentVisible;
623
630
  }
631
+ get conditionallyHidden() {
632
+ return this._conditionallyHidden || this._parentConditionallyHidden;
633
+ }
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) {
641
+ if (!this.hasCondition()) {
642
+ return false;
643
+ }
644
+ return !this.conditionallyVisible(data, row);
645
+ }
624
646
  get currentForm() {
625
647
  return this._currentForm;
626
648
  }
@@ -1791,7 +1813,7 @@ export default class Component extends Element {
1791
1813
  rebuild() {
1792
1814
  this.destroy();
1793
1815
  this.init();
1794
- this.visible = this.conditionallyVisible(null, null);
1816
+ this.visible = this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden;
1795
1817
  return this.redraw();
1796
1818
  }
1797
1819
  /**
@@ -1858,8 +1880,8 @@ export default class Component extends Element {
1858
1880
  conditionallyVisible(data, row) {
1859
1881
  data = data || this.rootValue;
1860
1882
  row = row || this.data;
1861
- if (this.builderMode || this.previewMode || !this.hasCondition()) {
1862
- return !this.component.hidden;
1883
+ if (this.builderMode || this.previewMode) {
1884
+ return true;
1863
1885
  }
1864
1886
  data = data || (this.root ? this.root.data : {});
1865
1887
  return this.checkCondition(row, data);
@@ -1889,8 +1911,14 @@ export default class Component extends Element {
1889
1911
  if (!this.builderMode & !this.previewMode && this.fieldLogic(data, row)) {
1890
1912
  this.redraw();
1891
1913
  }
1892
- // Check advanced conditions
1893
- const visible = this.conditionallyVisible(data, row);
1914
+ // Check advanced conditions (and cache the result)
1915
+ const isConditionallyHidden = this.checkConditionallyHidden(data, row) || this._parentConditionallyHidden;
1916
+ if (isConditionallyHidden !== this._conditionallyHidden) {
1917
+ this._conditionallyHidden = isConditionallyHidden;
1918
+ this.clearOnHide();
1919
+ }
1920
+ // Check visibility
1921
+ const visible = (this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden);
1894
1922
  if (this.visible !== visible) {
1895
1923
  this.visible = visible;
1896
1924
  }
@@ -2000,6 +2028,12 @@ export default class Component extends Element {
2000
2028
  FormioUtils.setActionProperty(newComponent, action, result, row, data, this);
2001
2029
  const property = action.property.value;
2002
2030
  if (!_.isEqual(_.get(this.component, property), _.get(newComponent, property))) {
2031
+ // Advanced Logic can modify the component's hidden property; because we track conditionally hidden state
2032
+ // separately from the component's hidden property, and technically this Advanced Logic conditionally hides
2033
+ // a component, we need to set _conditionallyHidden to the new value
2034
+ if (property === 'hidden') {
2035
+ this._conditionallyHidden = newComponent.hidden;
2036
+ }
2003
2037
  changed = true;
2004
2038
  }
2005
2039
  break;
@@ -2013,7 +2047,7 @@ export default class Component extends Element {
2013
2047
  component: newComponent,
2014
2048
  result,
2015
2049
  });
2016
- if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && !this.visible)) {
2050
+ if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden)) {
2017
2051
  this.setValue(newValue);
2018
2052
  if (this.viewOnly) {
2019
2053
  this.dataValue = newValue;
@@ -2046,7 +2080,7 @@ export default class Component extends Element {
2046
2080
  component: newComponent,
2047
2081
  result,
2048
2082
  }, 'value');
2049
- if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && !this.visible)) {
2083
+ if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden)) {
2050
2084
  this.setValue(newValue);
2051
2085
  if (this.viewOnly) {
2052
2086
  this.dataValue = newValue;
@@ -2157,7 +2191,7 @@ export default class Component extends Element {
2157
2191
  this.component.clearOnHide !== false &&
2158
2192
  !this.options.readOnly &&
2159
2193
  !this.options.showHiddenFields) {
2160
- if (!this.visible) {
2194
+ if (this.conditionallyHidden) {
2161
2195
  this.deleteValue();
2162
2196
  }
2163
2197
  else if (!this.hasValue() && this.shouldAddDefaultValue) {
@@ -2412,7 +2446,7 @@ export default class Component extends Element {
2412
2446
  */
2413
2447
  get dataValue() {
2414
2448
  if (!this.key ||
2415
- (!this.visible && this.component.clearOnHide && !this.rootPristine)) {
2449
+ (this.conditionallyHidden && this.component.clearOnHide && !this.rootPristine)) {
2416
2450
  return this.emptyValue;
2417
2451
  }
2418
2452
  if (!this.hasValue() && this.shouldAddDefaultValue) {
@@ -2431,7 +2465,7 @@ export default class Component extends Element {
2431
2465
  set dataValue(value) {
2432
2466
  if (!this.allowData ||
2433
2467
  !this.key ||
2434
- (!this.visible && this.component.clearOnHide && !this.rootPristine)) {
2468
+ (this.conditionallyHidden && this.component.clearOnHide && !this.rootPristine)) {
2435
2469
  return;
2436
2470
  }
2437
2471
  if ((value !== null) && (value !== undefined)) {
@@ -2751,7 +2785,7 @@ export default class Component extends Element {
2751
2785
  // If no calculated value or
2752
2786
  // hidden and set to clearOnHide (Don't calculate a value for a hidden field set to clear when hidden)
2753
2787
  const { clearOnHide } = this.component;
2754
- const shouldBeCleared = !this.visible && clearOnHide;
2788
+ const shouldBeCleared = this.conditionallyHidden && clearOnHide;
2755
2789
  const allowOverride = _.get(this.component, 'allowCalculateOverride', false);
2756
2790
  if (shouldBeCleared) {
2757
2791
  // remove calculated value so that the value is recalculated once component becomes visible
@@ -3396,7 +3430,7 @@ export default class Component extends Element {
3396
3430
  // If component definition changed, replace it.
3397
3431
  if (!_.isEqual(this.component, newComponent)) {
3398
3432
  this.component = newComponent;
3399
- const visible = this.conditionallyVisible(null, null);
3433
+ const visible = this.hasCondition() ? !this.conditionallyHidden : !this.component.hidden;
3400
3434
  const disabled = this.shouldDisabled;
3401
3435
  // Change states which won't be recalculated during redrawing
3402
3436
  if (this.visible !== visible) {
@@ -128,10 +128,10 @@ export default [
128
128
  {
129
129
  weight: 700,
130
130
  type: 'checkbox',
131
- label: 'Clear Value When Hidden',
131
+ label: 'Omit Value From Submission Data When Conditionally Hidden',
132
132
  key: 'clearOnHide',
133
133
  defaultValue: true,
134
- tooltip: 'When a field is hidden, clear the value.',
134
+ tooltip: 'When a field is conditionally hidden, omit the value from the submission data.',
135
135
  input: true
136
136
  },
137
137
  EditFormUtils.javaScriptValue('Custom Default Value', 'customDefaultValue', 'customDefaultValue', 1000, '<p><h4>Example:</h4><pre>value = data.firstName + " " + data.lastName;</pre></p>', '<p><h4>Example:</h4><pre>{"cat": [{"var": "data.firstName"}, " ", {"var": "data.lastName"}]}</pre>'),