@formio/js 5.1.0-dev.6068.e295b11 → 5.1.0-dev.6069.caec01d

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.
@@ -165,7 +165,6 @@ declare class Component extends Element {
165
165
  get componentsMap(): object;
166
166
  parentShouldConditionallyClear(): boolean;
167
167
  parentConditionallyHidden(): boolean;
168
- parentDefaultHidden(): boolean;
169
168
  set data(value: any);
170
169
  get data(): any;
171
170
  mergeSchema(component?: {}): any;
@@ -229,11 +228,8 @@ declare class Component extends Element {
229
228
  get visible(): boolean;
230
229
  get logicallyHidden(): any;
231
230
  _logicallyHidden: any;
232
- shouldConditionallyClearOnPristine(): boolean;
233
- shouldConditionallyClear(): boolean;
234
- _conditionallyClear: boolean | undefined;
235
- conditionallyHidden(): boolean;
236
- _conditionallyHidden: boolean | undefined;
231
+ shouldConditionallyClear(skipParent?: boolean): boolean;
232
+ conditionallyHidden(skipParent?: boolean): boolean;
237
233
  set currentForm(instance: any);
238
234
  get currentForm(): any;
239
235
  _currentForm: any;
@@ -461,8 +461,7 @@ class Component extends Element_1.default {
461
461
  parentShouldConditionallyClear() {
462
462
  let currentParent = this.parent;
463
463
  while (currentParent) {
464
- if ((currentParent.allowData && currentParent._conditionallyClear) ||
465
- (!currentParent.allowData && currentParent._conditionallyHidden)) {
464
+ if (currentParent.shouldConditionallyClear(true)) {
466
465
  return true;
467
466
  }
468
467
  currentParent = currentParent.parent;
@@ -472,17 +471,7 @@ class Component extends Element_1.default {
472
471
  parentConditionallyHidden() {
473
472
  let currentParent = this.parent;
474
473
  while (currentParent) {
475
- if (currentParent._conditionallyHidden) {
476
- return true;
477
- }
478
- currentParent = currentParent.parent;
479
- }
480
- return false;
481
- }
482
- parentDefaultHidden() {
483
- let currentParent = this.parent;
484
- while (currentParent) {
485
- if (currentParent.component.hidden) {
474
+ if (currentParent.conditionallyHidden(true)) {
486
475
  return true;
487
476
  }
488
477
  currentParent = currentParent.parent;
@@ -700,46 +689,48 @@ class Component extends Element_1.default {
700
689
  }
701
690
  return this._logicallyHidden;
702
691
  }
703
- shouldConditionallyClearOnPristine() {
704
- // If the form is pristine, we should NOT clear the value of a conditionally hidden child component
705
- // of a conditionally hidden layout component that defaults to hidden using the "hidden" property.
706
- return !this.parentDefaultHidden();
707
- }
708
- shouldConditionallyClear() {
692
+ shouldConditionallyClear(skipParent = false) {
709
693
  // Skip if this component has clearOnHide set to false.
710
694
  if (this.component.clearOnHide === false) {
711
- this._conditionallyClear = false;
712
- return this._conditionallyClear;
695
+ return false;
713
696
  }
714
697
  // If the component is logically hidden, then it is conditionally hidden and should clear.
715
698
  if (this.logicallyHidden) {
716
- this._conditionallyClear = true;
717
- return this._conditionallyClear;
699
+ return true;
718
700
  }
719
701
  // If we have a condition and it is not conditionally visible, the it should conditionally clear.
720
- if (this.hasCondition() &&
721
- !this.conditionallyVisible() &&
722
- (!this.rootPristine || this.shouldConditionallyClearOnPristine())) {
723
- this._conditionallyClear = true;
724
- return this._conditionallyClear;
702
+ if (this.hasCondition() && !this.conditionallyVisible()) {
703
+ return true;
704
+ }
705
+ if (skipParent) {
706
+ // Stop recurrsion for the parent checks.
707
+ return false;
725
708
  }
726
- this._conditionallyClear = this.hasSetValue ? false : this.parentShouldConditionallyClear();
727
- return this._conditionallyClear;
709
+ // If this component has a set value, then it should ONLY clear if a parent is hidden
710
+ // and has the clearOnHide set to true.
711
+ if (this.hasSetValue) {
712
+ return this.parentShouldConditionallyClear();
713
+ }
714
+ // Clear the value if the parent is conditionally hidden.
715
+ return this.parentConditionallyHidden();
728
716
  }
729
- conditionallyHidden() {
730
- // If it is logically hidden, then it is conditionally hidden.
717
+ conditionallyHidden(skipParent = false) {
731
718
  if (this.logicallyHidden) {
732
- this._conditionallyHidden = true;
733
- return this._conditionallyHidden;
719
+ return true;
734
720
  }
735
- // If it has a condition, and is not conditionally visible, then it is conditionally hidden.
736
- if (this.hasCondition() && !this.conditionallyVisible()) {
737
- this._conditionallyHidden = true;
738
- return this._conditionallyHidden;
721
+ if (!this.hasCondition() && !skipParent) {
722
+ return this.parentConditionallyHidden();
723
+ }
724
+ // Return if we are not conditionally visible (conditionallyHidden)
725
+ if (!this.conditionallyVisible()) {
726
+ return true;
727
+ }
728
+ if (skipParent) {
729
+ // Stop recurrsion for the parent checks.
730
+ return false;
739
731
  }
740
- // It is conditionally hidden if its parent is conditionally hidden.
741
- this._conditionallyHidden = this.parentConditionallyHidden();
742
- return this._conditionallyHidden;
732
+ // Check the parent.
733
+ return this.parentConditionallyHidden();
743
734
  }
744
735
  get currentForm() {
745
736
  return this._currentForm;
@@ -98,6 +98,7 @@ export default class FormComponent extends Component {
98
98
  * @returns {void}
99
99
  */
100
100
  onSetSubFormValue(submission: object | null | undefined, flags: object | null | undefined): void;
101
+ areAllComponentsEmpty(data: any): boolean;
101
102
  updateSubFormVisibility(): void;
102
103
  /**
103
104
  * Determines if this form is a Nested Wizard
@@ -101,9 +101,6 @@ class FormComponent extends Component_1.default {
101
101
  }
102
102
  return this.createSubForm();
103
103
  }
104
- shouldConditionallyClearOnPristine() {
105
- return !this.hasSetValue && super.shouldConditionallyClearOnPristine();
106
- }
107
104
  get dataReady() {
108
105
  var _a;
109
106
  return ((_a = this.subForm) === null || _a === void 0 ? void 0 : _a.dataReady) || this.subFormReady || Promise.resolve();
@@ -293,13 +290,11 @@ class FormComponent extends Component_1.default {
293
290
  }
294
291
  this.subForm.attach(element);
295
292
  this.valueChanged = this.hasSetValue;
296
- if (!this.shouldConditionallyClear()) {
297
- if (!this.valueChanged && this.dataValue.state !== 'submitted') {
298
- this.setDefaultValue();
299
- }
300
- else {
301
- this.restoreValue();
302
- }
293
+ if (!this.valueChanged && this.dataValue.state !== 'submitted') {
294
+ this.setDefaultValue();
295
+ }
296
+ else {
297
+ this.restoreValue();
303
298
  }
304
299
  }
305
300
  if (!this.builderMode && this.component.modalEdit) {
@@ -416,7 +411,7 @@ class FormComponent extends Component_1.default {
416
411
  lodash_1.default.assign(componentsMap, formComponentsMap);
417
412
  this.component.components = this.subForm.components.map((comp) => comp.component);
418
413
  this.subForm.on('change', () => {
419
- if (this.subForm && !this.shouldConditionallyClear()) {
414
+ if (this.subForm) {
420
415
  this.dataValue = this.subForm.getValue();
421
416
  this.triggerChange({
422
417
  noEmit: true
@@ -684,7 +679,20 @@ class FormComponent extends Component_1.default {
684
679
  }
685
680
  }
686
681
  isEmpty(value = this.dataValue) {
687
- return value === null || lodash_1.default.isEqual(value, this.emptyValue);
682
+ return value === null || lodash_1.default.isEqual(value, this.emptyValue) || (this.areAllComponentsEmpty(value === null || value === void 0 ? void 0 : value.data) && !(value === null || value === void 0 ? void 0 : value._id));
683
+ }
684
+ areAllComponentsEmpty(data) {
685
+ let res = true;
686
+ if (this.subForm) {
687
+ this.subForm.everyComponent((comp) => {
688
+ const componentValue = lodash_1.default.get(data, comp.key);
689
+ res &= comp.isEmpty(componentValue);
690
+ });
691
+ }
692
+ else {
693
+ res = false;
694
+ }
695
+ return res;
688
696
  }
689
697
  getValue() {
690
698
  if (this.subForm) {
@@ -26,8 +26,8 @@ export const getBestMatch: typeof Utils.getBestMatch;
26
26
  export const getComponentFromPath: typeof Utils.getComponentFromPath;
27
27
  export const getComponentValue: typeof Utils.getComponentValue;
28
28
  export const findComponents: typeof Utils.findComponents;
29
- export const eachComponentDataAsync: (components: Component[], data: DataObject, fn: EachComponentDataAsyncCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: any, parentPaths?: any) => Promise<void>;
30
- export const eachComponentData: (components: Component[], data: DataObject, fn: EachComponentDataCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: any, parentPaths?: any) => void;
29
+ export const eachComponentDataAsync: (components: import("@formio/core").Component[], data: import("@formio/core").DataObject, fn: import("@formio/core").EachComponentDataAsyncCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: import("@formio/core").Component | undefined, parentPaths?: import("@formio/core").ComponentPaths | undefined) => Promise<void>;
30
+ export const eachComponentData: (components: import("@formio/core").Component[], data: import("@formio/core").DataObject, fn: import("@formio/core").EachComponentDataCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: import("@formio/core").Component | undefined, parentPaths?: import("@formio/core").ComponentPaths | undefined) => void;
31
31
  export const getComponentKey: typeof Utils.getComponentKey;
32
32
  export const getContextualRowPath: typeof Utils.getContextualRowPath;
33
33
  export const getContextualRowData: typeof Utils.getContextualRowData;
@@ -34,6 +34,7 @@ const Evaluator_1 = require("./Evaluator");
34
34
  Object.defineProperty(exports, "Evaluator", { enumerable: true, get: function () { return Evaluator_1.Evaluator; } });
35
35
  const conditionOperators_1 = __importDefault(require("./conditionOperators"));
36
36
  exports.ConditionOperators = conditionOperators_1.default;
37
+ const core_1 = require("@formio/core");
37
38
  const interpolate = Evaluator_1.Evaluator.interpolate;
38
39
  exports.interpolate = interpolate;
39
40
  __exportStar(require("./formUtils"), exports);
@@ -271,7 +272,7 @@ function checkSimpleConditional(component, condition, row, data, instance) {
271
272
  default:
272
273
  result = lodash_1.default.every(conditionsResult.flat(), res => !!res);
273
274
  }
274
- return show ? result : !result;
275
+ return (0, core_1.convertShowToBoolean)(show) ? result : !result;
275
276
  }
276
277
  }
277
278
  exports.checkSimpleConditional = checkSimpleConditional;
@@ -165,7 +165,6 @@ declare class Component extends Element {
165
165
  get componentsMap(): object;
166
166
  parentShouldConditionallyClear(): boolean;
167
167
  parentConditionallyHidden(): boolean;
168
- parentDefaultHidden(): boolean;
169
168
  set data(value: any);
170
169
  get data(): any;
171
170
  mergeSchema(component?: {}): any;
@@ -229,11 +228,8 @@ declare class Component extends Element {
229
228
  get visible(): boolean;
230
229
  get logicallyHidden(): any;
231
230
  _logicallyHidden: any;
232
- shouldConditionallyClearOnPristine(): boolean;
233
- shouldConditionallyClear(): boolean;
234
- _conditionallyClear: boolean | undefined;
235
- conditionallyHidden(): boolean;
236
- _conditionallyHidden: boolean | undefined;
231
+ shouldConditionallyClear(skipParent?: boolean): boolean;
232
+ conditionallyHidden(skipParent?: boolean): boolean;
237
233
  set currentForm(instance: any);
238
234
  get currentForm(): any;
239
235
  _currentForm: any;
@@ -425,8 +425,7 @@ export default class Component extends Element {
425
425
  parentShouldConditionallyClear() {
426
426
  let currentParent = this.parent;
427
427
  while (currentParent) {
428
- if ((currentParent.allowData && currentParent._conditionallyClear) ||
429
- (!currentParent.allowData && currentParent._conditionallyHidden)) {
428
+ if (currentParent.shouldConditionallyClear(true)) {
430
429
  return true;
431
430
  }
432
431
  currentParent = currentParent.parent;
@@ -436,17 +435,7 @@ export default class Component extends Element {
436
435
  parentConditionallyHidden() {
437
436
  let currentParent = this.parent;
438
437
  while (currentParent) {
439
- if (currentParent._conditionallyHidden) {
440
- return true;
441
- }
442
- currentParent = currentParent.parent;
443
- }
444
- return false;
445
- }
446
- parentDefaultHidden() {
447
- let currentParent = this.parent;
448
- while (currentParent) {
449
- if (currentParent.component.hidden) {
438
+ if (currentParent.conditionallyHidden(true)) {
450
439
  return true;
451
440
  }
452
441
  currentParent = currentParent.parent;
@@ -664,46 +653,48 @@ export default class Component extends Element {
664
653
  }
665
654
  return this._logicallyHidden;
666
655
  }
667
- shouldConditionallyClearOnPristine() {
668
- // If the form is pristine, we should NOT clear the value of a conditionally hidden child component
669
- // of a conditionally hidden layout component that defaults to hidden using the "hidden" property.
670
- return !this.parentDefaultHidden();
671
- }
672
- shouldConditionallyClear() {
656
+ shouldConditionallyClear(skipParent = false) {
673
657
  // Skip if this component has clearOnHide set to false.
674
658
  if (this.component.clearOnHide === false) {
675
- this._conditionallyClear = false;
676
- return this._conditionallyClear;
659
+ return false;
677
660
  }
678
661
  // If the component is logically hidden, then it is conditionally hidden and should clear.
679
662
  if (this.logicallyHidden) {
680
- this._conditionallyClear = true;
681
- return this._conditionallyClear;
663
+ return true;
682
664
  }
683
665
  // If we have a condition and it is not conditionally visible, the it should conditionally clear.
684
- if (this.hasCondition() &&
685
- !this.conditionallyVisible() &&
686
- (!this.rootPristine || this.shouldConditionallyClearOnPristine())) {
687
- this._conditionallyClear = true;
688
- return this._conditionallyClear;
666
+ if (this.hasCondition() && !this.conditionallyVisible()) {
667
+ return true;
668
+ }
669
+ if (skipParent) {
670
+ // Stop recurrsion for the parent checks.
671
+ return false;
689
672
  }
690
- this._conditionallyClear = this.hasSetValue ? false : this.parentShouldConditionallyClear();
691
- return this._conditionallyClear;
673
+ // If this component has a set value, then it should ONLY clear if a parent is hidden
674
+ // and has the clearOnHide set to true.
675
+ if (this.hasSetValue) {
676
+ return this.parentShouldConditionallyClear();
677
+ }
678
+ // Clear the value if the parent is conditionally hidden.
679
+ return this.parentConditionallyHidden();
692
680
  }
693
- conditionallyHidden() {
694
- // If it is logically hidden, then it is conditionally hidden.
681
+ conditionallyHidden(skipParent = false) {
695
682
  if (this.logicallyHidden) {
696
- this._conditionallyHidden = true;
697
- return this._conditionallyHidden;
683
+ return true;
698
684
  }
699
- // If it has a condition, and is not conditionally visible, then it is conditionally hidden.
700
- if (this.hasCondition() && !this.conditionallyVisible()) {
701
- this._conditionallyHidden = true;
702
- return this._conditionallyHidden;
685
+ if (!this.hasCondition() && !skipParent) {
686
+ return this.parentConditionallyHidden();
687
+ }
688
+ // Return if we are not conditionally visible (conditionallyHidden)
689
+ if (!this.conditionallyVisible()) {
690
+ return true;
691
+ }
692
+ if (skipParent) {
693
+ // Stop recurrsion for the parent checks.
694
+ return false;
703
695
  }
704
- // It is conditionally hidden if its parent is conditionally hidden.
705
- this._conditionallyHidden = this.parentConditionallyHidden();
706
- return this._conditionallyHidden;
696
+ // Check the parent.
697
+ return this.parentConditionallyHidden();
707
698
  }
708
699
  get currentForm() {
709
700
  return this._currentForm;
@@ -98,6 +98,7 @@ export default class FormComponent extends Component {
98
98
  * @returns {void}
99
99
  */
100
100
  onSetSubFormValue(submission: object | null | undefined, flags: object | null | undefined): void;
101
+ areAllComponentsEmpty(data: any): boolean;
101
102
  updateSubFormVisibility(): void;
102
103
  /**
103
104
  * Determines if this form is a Nested Wizard
@@ -96,9 +96,6 @@ export default class FormComponent extends Component {
96
96
  }
97
97
  return this.createSubForm();
98
98
  }
99
- shouldConditionallyClearOnPristine() {
100
- return !this.hasSetValue && super.shouldConditionallyClearOnPristine();
101
- }
102
99
  get dataReady() {
103
100
  return this.subForm?.dataReady || this.subFormReady || Promise.resolve();
104
101
  }
@@ -289,13 +286,11 @@ export default class FormComponent extends Component {
289
286
  }
290
287
  this.subForm.attach(element);
291
288
  this.valueChanged = this.hasSetValue;
292
- if (!this.shouldConditionallyClear()) {
293
- if (!this.valueChanged && this.dataValue.state !== 'submitted') {
294
- this.setDefaultValue();
295
- }
296
- else {
297
- this.restoreValue();
298
- }
289
+ if (!this.valueChanged && this.dataValue.state !== 'submitted') {
290
+ this.setDefaultValue();
291
+ }
292
+ else {
293
+ this.restoreValue();
299
294
  }
300
295
  }
301
296
  if (!this.builderMode && this.component.modalEdit) {
@@ -410,7 +405,7 @@ export default class FormComponent extends Component {
410
405
  _.assign(componentsMap, formComponentsMap);
411
406
  this.component.components = this.subForm.components.map((comp) => comp.component);
412
407
  this.subForm.on('change', () => {
413
- if (this.subForm && !this.shouldConditionallyClear()) {
408
+ if (this.subForm) {
414
409
  this.dataValue = this.subForm.getValue();
415
410
  this.triggerChange({
416
411
  noEmit: true
@@ -673,7 +668,20 @@ export default class FormComponent extends Component {
673
668
  }
674
669
  }
675
670
  isEmpty(value = this.dataValue) {
676
- return value === null || _.isEqual(value, this.emptyValue);
671
+ return value === null || _.isEqual(value, this.emptyValue) || (this.areAllComponentsEmpty(value?.data) && !value?._id);
672
+ }
673
+ areAllComponentsEmpty(data) {
674
+ let res = true;
675
+ if (this.subForm) {
676
+ this.subForm.everyComponent((comp) => {
677
+ const componentValue = _.get(data, comp.key);
678
+ res &= comp.isEmpty(componentValue);
679
+ });
680
+ }
681
+ else {
682
+ res = false;
683
+ }
684
+ return res;
677
685
  }
678
686
  getValue() {
679
687
  if (this.subForm) {
@@ -26,8 +26,8 @@ export const getBestMatch: typeof Utils.getBestMatch;
26
26
  export const getComponentFromPath: typeof Utils.getComponentFromPath;
27
27
  export const getComponentValue: typeof Utils.getComponentValue;
28
28
  export const findComponents: typeof Utils.findComponents;
29
- export const eachComponentDataAsync: (components: Component[], data: DataObject, fn: EachComponentDataAsyncCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: any, parentPaths?: any) => Promise<void>;
30
- export const eachComponentData: (components: Component[], data: DataObject, fn: EachComponentDataCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: any, parentPaths?: any) => void;
29
+ export const eachComponentDataAsync: (components: import("@formio/core").Component[], data: import("@formio/core").DataObject, fn: import("@formio/core").EachComponentDataAsyncCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: import("@formio/core").Component | undefined, parentPaths?: import("@formio/core").ComponentPaths | undefined) => Promise<void>;
30
+ export const eachComponentData: (components: import("@formio/core").Component[], data: import("@formio/core").DataObject, fn: import("@formio/core").EachComponentDataCallback, includeAll?: boolean | undefined, local?: boolean | undefined, parent?: import("@formio/core").Component | undefined, parentPaths?: import("@formio/core").ComponentPaths | undefined) => void;
31
31
  export const getComponentKey: typeof Utils.getComponentKey;
32
32
  export const getContextualRowPath: typeof Utils.getContextualRowPath;
33
33
  export const getContextualRowData: typeof Utils.getContextualRowData;
@@ -8,6 +8,7 @@ import dompurify from 'dompurify';
8
8
  import { getValue } from './formUtils';
9
9
  import { Evaluator } from './Evaluator';
10
10
  import ConditionOperators from './conditionOperators';
11
+ import { convertShowToBoolean } from '@formio/core';
11
12
  const interpolate = Evaluator.interpolate;
12
13
  export * from './formUtils';
13
14
  // Configure JsonLogic
@@ -236,7 +237,7 @@ export function checkSimpleConditional(component, condition, row, data, instance
236
237
  default:
237
238
  result = _.every(conditionsResult.flat(), res => !!res);
238
239
  }
239
- return show ? result : !result;
240
+ return convertShowToBoolean(show) ? result : !result;
240
241
  }
241
242
  }
242
243
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6068.e295b11",
3
+ "version": "5.1.0-dev.6069.caec01d",
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
  "homepage": "https://github.com/formio/formio.js#readme",
82
82
  "dependencies": {
83
83
  "@formio/bootstrap": "v3.0.0-dev.121.085d187",
84
- "@formio/core": "v2.4.0-dev.2",
84
+ "@formio/core": "v2.4.0-dev.232.d91b1e4",
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",