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

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 +18 -18
  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 +18 -18
  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 +11 -11
  11. package/dist/formio.min.js +1 -1
  12. package/dist/formio.min.js.LICENSE.txt +1 -1
  13. package/dist/formio.utils.js +9 -9
  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
@@ -81,17 +81,26 @@ 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();
84
85
  const forceShow = this.shouldForceShow();
85
86
  const forceHide = this.shouldForceHide();
86
- this.components.forEach(component => {
87
+ this.components.forEach((component) => {
87
88
  // Set the parent visibility first since we may have nested components within nested components
88
89
  // and they need to be able to determine their visibility based on the parent visibility.
89
90
  component.parentVisible = isVisible;
90
- const conditionallyVisible = component.conditionallyVisible();
91
- if (forceShow || conditionallyVisible) {
91
+ component._parentConditionallyHidden = isConditionallyHidden;
92
+ let visible;
93
+ if (component.hasCondition()) {
94
+ component._conditionallyHidden = component.checkConditionallyHidden() || component._parentConditionallyHidden;
95
+ visible = !component.conditionallyHidden;
96
+ }
97
+ else {
98
+ visible = !component.component.hidden;
99
+ }
100
+ if (forceShow || visible) {
92
101
  component.visible = true;
93
102
  }
94
- else if (forceHide || !isVisible || !conditionallyVisible) {
103
+ else if (forceHide || !isVisible || !visible) {
95
104
  component.visible = false;
96
105
  }
97
106
  // If hiding a nested component, clear all errors below.
@@ -100,7 +109,6 @@ export default class NestedComponent extends Field {
100
109
  }
101
110
  });
102
111
  if (visibilityChanged) {
103
- this.clearOnHide();
104
112
  this.redraw();
105
113
  }
106
114
  }
@@ -365,6 +373,7 @@ export default class NestedComponent extends Field {
365
373
  data = data || this.data;
366
374
  options.parent = this;
367
375
  options.parentVisible = this.visible;
376
+ options.parentConditionallyHidden = this.conditionallyHidden;
368
377
  options.root = options?.root || this.root || this;
369
378
  options.localRoot = this.localRoot;
370
379
  options.skipInit = true;
@@ -623,7 +632,7 @@ export default class NestedComponent extends Field {
623
632
  clearOnHide(show) {
624
633
  super.clearOnHide(show);
625
634
  if (this.component.clearOnHide) {
626
- if (this.allowData && !this.hasValue() && !(this.options.server && !this.visible)) {
635
+ if (this.allowData && !this.hasValue() && !this.conditionallyHidden) {
627
636
  this.dataValue = this.defaultValue;
628
637
  }
629
638
  if (this.hasValue()) {
@@ -652,7 +661,7 @@ export default class NestedComponent extends Field {
652
661
  }
653
662
  calculateValue(data, flags, row) {
654
663
  // Do not iterate into children and calculateValues if this nested component is conditionally hidden.
655
- if (!this.conditionallyVisible()) {
664
+ if (this.conditionallyHidden) {
656
665
  return false;
657
666
  }
658
667
  return this.getComponents().reduce((changed, comp) => comp.calculateValue(data, flags, row) || changed, super.calculateValue(data, flags, row));
@@ -69,7 +69,7 @@ export default class DataMapComponent extends DataGridComponent {
69
69
  }
70
70
  get dataValue() {
71
71
  if (!this.key ||
72
- (!this.visible && this.component.clearOnHide)) {
72
+ (this.conditionallyHidden && this.component.clearOnHide)) {
73
73
  return this.emptyValue;
74
74
  }
75
75
  if (!this.hasValue() && this.shouldAddDefaultValue) {
@@ -1132,7 +1132,7 @@ export default class EditGridComponent extends NestedArrayComponent {
1132
1132
  }
1133
1133
  }
1134
1134
  const changed = this.hasChanged(value, this.dataValue);
1135
- if (this.parent && !this.options.server) {
1135
+ if (this.parent) {
1136
1136
  this.parent.checkComponentConditions();
1137
1137
  }
1138
1138
  this.dataValue = value;
@@ -1165,10 +1165,7 @@ export default class EditGridComponent extends NestedArrayComponent {
1165
1165
  this.editRows = this.editRows.slice(0, dataLength);
1166
1166
  this.openWhenEmpty();
1167
1167
  this.updateOnChange(flags, changed);
1168
- // do not call checkData with server option, it is called when change is triggered in updateOnChange
1169
- if (!this.options.server) {
1170
- this.checkData();
1171
- }
1168
+ this.checkData();
1172
1169
  this.changeState(changed, flags);
1173
1170
  return changed;
1174
1171
  }
@@ -421,10 +421,11 @@ export default class FormComponent extends Component {
421
421
  return this.subFormReady;
422
422
  }
423
423
  hideSubmitButton(component) {
424
- const isSubmitButton = (component.type === 'button') &&
425
- ((component.action === 'submit') || !component.action);
424
+ const isSubmitButton = component.type === 'button' && (component.action === 'submit' || !component.action);
426
425
  if (isSubmitButton) {
427
426
  component.hidden = true;
427
+ // clearOnHide no longer clears from the JSON `hidden` flag, so we make the button conditionally hidden to clear its data
428
+ component.customConditional = 'show = false';
428
429
  }
429
430
  }
430
431
  /**
@@ -433,7 +434,7 @@ export default class FormComponent extends Component {
433
434
  * @returns {Promise} - The promise that resolves when the subform is loaded.
434
435
  */
435
436
  loadSubForm(fromAttach) {
436
- if (this.builderMode || this.isHidden() || (this.isSubFormLazyLoad() && !fromAttach)) {
437
+ if (this.builderMode || this.conditionallyHidden || (this.isSubFormLazyLoad() && !fromAttach)) {
437
438
  return Promise.resolve();
438
439
  }
439
440
  if (this.hasLoadedForm && !this.isRevisionChanged &&
@@ -505,7 +506,7 @@ export default class FormComponent extends Component {
505
506
  * @returns {*|boolean} - TRUE if the subform should be submitted, FALSE if it should not.
506
507
  */
507
508
  get shouldSubmit() {
508
- return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && !this.isHidden();
509
+ return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && !this.conditionallyHidden;
509
510
  }
510
511
  /**
511
512
  * Returns the data for the subform.
@@ -51,9 +51,21 @@ export default class HTMLComponent extends Component {
51
51
  }
52
52
  checkRefreshOn(changed) {
53
53
  super.checkRefreshOn(changed);
54
- if (!this.builderMode && this.component.refreshOnChange && this.element &&
55
- !_.isUndefined(changed) && ((_.isBoolean(changed) && changed) || !_.isEmpty(changed)) &&
56
- this.conditionallyVisible(this.data, this.row)) {
54
+ let visible;
55
+ if (this.hasCondition()) {
56
+ this._conditionallyHidden = this.checkConditionallyHidden();
57
+ visible = !this.conditionallyHidden;
58
+ }
59
+ else {
60
+ visible = !this.component.hidden;
61
+ }
62
+ const shouldSetContent = !this.builderMode
63
+ && this.component.refreshOnChange
64
+ && this.element
65
+ && !_.isUndefined(changed)
66
+ && ((_.isBoolean(changed) && changed) || !_.isEmpty(changed))
67
+ && visible;
68
+ if (shouldSetContent) {
57
69
  this.setContent(this.element, this.renderContent());
58
70
  }
59
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-rc.1",
3
+ "version": "5.1.0-rc.2",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {
@@ -81,7 +81,7 @@
81
81
  "dependencies": {
82
82
  "@formio/bootstrap": "3.1.0-rc.1",
83
83
  "@formio/choices.js": "^10.2.1",
84
- "@formio/core": "2.4.0-rc.1",
84
+ "@formio/core": "2.4.0-rc.2",
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",