@formio/js 5.1.0-dev.6061.f2b1042 → 5.1.0-dev.6064.1c8db05

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.
@@ -389,7 +389,7 @@ export default class Component extends Element {
389
389
  if (this.allowData && this.key) {
390
390
  this.options.name += `[${this.key}]`;
391
391
  // If component is visible or not set to clear on hide, set the default value.
392
- if (!(this.conditionallyHidden() && this.component.clearOnHide)) {
392
+ if (!this.shouldConditionallyClear()) {
393
393
  if (!this.hasValue()) {
394
394
  if (this.shouldAddDefaultValue) {
395
395
  this.dataValue = this.defaultValue;
@@ -422,6 +422,16 @@ export default class Component extends Element {
422
422
  get componentsMap() {
423
423
  return this.root?.childComponentsMap || {};
424
424
  }
425
+ parentShouldConditionallyClear() {
426
+ let currentParent = this.parent;
427
+ while (currentParent) {
428
+ if (currentParent.shouldConditionallyClear(true)) {
429
+ return true;
430
+ }
431
+ currentParent = currentParent.parent;
432
+ }
433
+ return false;
434
+ }
425
435
  parentConditionallyHidden() {
426
436
  let currentParent = this.parent;
427
437
  while (currentParent) {
@@ -643,11 +653,48 @@ export default class Component extends Element {
643
653
  }
644
654
  return this._logicallyHidden;
645
655
  }
656
+ shouldConditionallyClear(skipParent = false) {
657
+ // Skip if this component has clearOnHide set to false.
658
+ if (this.component.clearOnHide === false) {
659
+ return false;
660
+ }
661
+ // If the component is logically hidden, then it is conditionally hidden and should clear.
662
+ if (this.logicallyHidden) {
663
+ return true;
664
+ }
665
+ // If we have a condition and it is not conditionally visible, the it should conditionally clear.
666
+ if (this.hasCondition() && !this.conditionallyVisible()) {
667
+ return true;
668
+ }
669
+ if (skipParent) {
670
+ // Stop recurrsion for the parent checks.
671
+ return false;
672
+ }
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();
680
+ }
646
681
  conditionallyHidden(skipParent = false) {
647
- if (!this.hasCondition()) {
648
- return this.logicallyHidden || (skipParent ? false : this.parentConditionallyHidden());
682
+ if (this.logicallyHidden) {
683
+ return true;
684
+ }
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;
649
695
  }
650
- return !this.conditionallyVisible() || this.logicallyHidden || (skipParent ? false : this.parentConditionallyHidden());
696
+ // Check the parent.
697
+ return this.parentConditionallyHidden();
651
698
  }
652
699
  get currentForm() {
653
700
  return this._currentForm;
@@ -2046,7 +2093,7 @@ export default class Component extends Element {
2046
2093
  component: newComponent,
2047
2094
  result,
2048
2095
  });
2049
- if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden())) {
2096
+ if (!_.isEqual(oldValue, newValue) && !this.shouldConditionallyClear()) {
2050
2097
  this.setValue(newValue);
2051
2098
  if (this.viewOnly) {
2052
2099
  this.dataValue = newValue;
@@ -2079,7 +2126,7 @@ export default class Component extends Element {
2079
2126
  component: newComponent,
2080
2127
  result,
2081
2128
  }, 'value');
2082
- if (!_.isEqual(oldValue, newValue) && !(this.component.clearOnHide && this.conditionallyHidden())) {
2129
+ if (!_.isEqual(oldValue, newValue) && !this.shouldConditionallyClear()) {
2083
2130
  this.setValue(newValue);
2084
2131
  if (this.viewOnly) {
2085
2132
  this.dataValue = newValue;
@@ -2185,7 +2232,7 @@ export default class Component extends Element {
2185
2232
  clearComponentOnHide() {
2186
2233
  // clearOnHide defaults to true for old forms (without the value set) so only trigger if the value is false.
2187
2234
  if (this.component.clearOnHide !== false && !this.options.readOnly && !this.options.showHiddenFields) {
2188
- if (this.conditionallyHidden()) {
2235
+ if (this.shouldConditionallyClear()) {
2189
2236
  this.deleteValue();
2190
2237
  }
2191
2238
  else if (!this.hasValue() && this.shouldAddDefaultValue) {
@@ -2518,14 +2565,17 @@ export default class Component extends Element {
2518
2565
  (this.component.defaultValue !== null) &&
2519
2566
  (this.component.defaultValue !== undefined));
2520
2567
  }
2568
+ /**
2569
+ * Determine if we should add a default value for this component.
2570
+ * @returns {boolean} - TRUE if a default value should be set
2571
+ */
2521
2572
  get shouldAddDefaultValue() {
2522
- // It should add a default value if...
2523
- // 1.) The component is pristine (user has not manually modified it). AND
2524
- // 1.) There is a default value setting present OR
2525
- // 2.) The noDefaults flag is not true AND the empty value is either an empty string or boolean
2526
- return this.pristine && (this.hasDefaultValue ||
2527
- (!this.options.noDefaults && (this.emptyValue === '' || (typeof this.emptyValue === 'boolean'))));
2573
+ return this.pristine && this.allowData && (this.hasDefaultValue || !this.options.noDefaults);
2528
2574
  }
2575
+ /**
2576
+ * Get the default value of this component.
2577
+ * @returns {*} - The default value for this component.
2578
+ */
2529
2579
  get defaultValue() {
2530
2580
  let defaultValue = this.emptyValue;
2531
2581
  if (this.component.defaultValue) {
@@ -2795,10 +2845,8 @@ export default class Component extends Element {
2795
2845
  }
2796
2846
  // If no calculated value or
2797
2847
  // hidden and set to clearOnHide (Don't calculate a value for a hidden field set to clear when hidden)
2798
- const { clearOnHide } = this.component;
2799
- const shouldBeCleared = this.conditionallyHidden() && clearOnHide;
2800
2848
  const allowOverride = _.get(this.component, 'allowCalculateOverride', false);
2801
- if (shouldBeCleared) {
2849
+ if (this.shouldConditionallyClear()) {
2802
2850
  // remove calculated value so that the value is recalculated once component becomes visible
2803
2851
  if (this.hasOwnProperty('calculatedValue') && allowOverride) {
2804
2852
  _.unset(this, 'calculatedValue');
@@ -8,6 +8,7 @@ declare const _default: ({
8
8
  customConditional: ({ data }: {
9
9
  data: any;
10
10
  }) => boolean;
11
+ defaultValue?: undefined;
11
12
  placeholder?: undefined;
12
13
  validate?: undefined;
13
14
  } | {
@@ -15,6 +16,7 @@ declare const _default: ({
15
16
  type: string;
16
17
  input: boolean;
17
18
  key: string;
19
+ defaultValue: string;
18
20
  label: string;
19
21
  placeholder: string;
20
22
  tooltip: string;
@@ -32,6 +34,7 @@ declare const _default: ({
32
34
  label: string;
33
35
  tooltip: string;
34
36
  customConditional?: undefined;
37
+ defaultValue?: undefined;
35
38
  placeholder?: undefined;
36
39
  validate?: undefined;
37
40
  } | {
@@ -45,6 +48,7 @@ declare const _default: ({
45
48
  customConditional: ({ data }: {
46
49
  data: any;
47
50
  }) => any;
51
+ defaultValue?: undefined;
48
52
  validate?: undefined;
49
53
  })[];
50
54
  export default _default;
@@ -13,6 +13,7 @@ export default [
13
13
  type: 'textfield',
14
14
  input: true,
15
15
  key: 'switchToManualModeLabel',
16
+ defaultValue: 'Can\'t find address? Switch to manual mode.',
16
17
  label: 'Switch To Manual Mode Label',
17
18
  placeholder: 'Switch To Manual Mode Label',
18
19
  tooltip: 'The label for the checkbox used to switch to manual mode.',
@@ -517,7 +517,7 @@ export default class FormComponent extends Component {
517
517
  * @returns {*|boolean} - TRUE if the subform should be submitted, FALSE if it should not.
518
518
  */
519
519
  get shouldSubmit() {
520
- return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && (!this.conditionallyHidden() || !this.component.clearOnHide);
520
+ return this.subFormReady && (!this.component.hasOwnProperty('reference') || this.component.reference) && !this.shouldConditionallyClear();
521
521
  }
522
522
  /**
523
523
  * Returns the data for the subform.
@@ -9,100 +9,16 @@ declare const _default: ({
9
9
  custom?: undefined;
10
10
  };
11
11
  type?: undefined;
12
+ as?: undefined;
13
+ editor?: undefined;
12
14
  weight?: undefined;
13
15
  input?: undefined;
14
16
  label?: undefined;
15
17
  tooltip?: undefined;
16
- conditional?: undefined;
17
- as?: undefined;
18
- editor?: undefined;
19
- defaultValue?: undefined;
20
18
  description?: undefined;
19
+ conditional?: undefined;
21
20
  reorder?: undefined;
22
- components?: undefined;
23
- dataSrc?: undefined;
24
- authenticate?: undefined;
25
- template?: undefined;
26
- valueProperty?: undefined;
27
- clearOnHide?: undefined;
28
- lazyLoad?: undefined;
29
- skipMerge?: undefined;
30
- refreshOn?: undefined;
31
- onSetItems?: undefined;
32
- onChange?: undefined;
33
- placeholder?: undefined;
34
- validate?: undefined;
35
- delimiter?: undefined;
36
- requireDecimal?: undefined;
37
- encrypted?: undefined;
38
- rows?: undefined;
39
- mask?: undefined;
40
- tableView?: undefined;
41
- alwaysEnabled?: undefined;
42
- } | {
43
- type: string;
44
- weight: number;
45
- input: boolean;
46
- key: string;
47
- label: string;
48
- tooltip: string;
49
- conditional: {
50
- json: {
51
- '===': (string | {
52
- var: string;
53
- })[];
54
- and?: undefined;
55
- in?: undefined;
56
- };
57
- };
58
- data?: undefined;
59
- as?: undefined;
60
- editor?: undefined;
61
21
  defaultValue?: undefined;
62
- description?: undefined;
63
- reorder?: undefined;
64
- components?: undefined;
65
- dataSrc?: undefined;
66
- authenticate?: undefined;
67
- template?: undefined;
68
- valueProperty?: undefined;
69
- clearOnHide?: undefined;
70
- lazyLoad?: undefined;
71
- skipMerge?: undefined;
72
- refreshOn?: undefined;
73
- onSetItems?: undefined;
74
- onChange?: undefined;
75
- placeholder?: undefined;
76
- validate?: undefined;
77
- delimiter?: undefined;
78
- requireDecimal?: undefined;
79
- encrypted?: undefined;
80
- rows?: undefined;
81
- mask?: undefined;
82
- tableView?: undefined;
83
- alwaysEnabled?: undefined;
84
- } | {
85
- type: string;
86
- as: string;
87
- editor: string;
88
- weight: number;
89
- input: boolean;
90
- key: string;
91
- label: string;
92
- tooltip: string;
93
- defaultValue: {};
94
- conditional: {
95
- json: {
96
- '===': (string | {
97
- var: string;
98
- })[];
99
- and?: undefined;
100
- in?: undefined;
101
- };
102
- };
103
- data?: undefined;
104
- description?: undefined;
105
- reorder?: undefined;
106
22
  components?: undefined;
107
23
  dataSrc?: undefined;
108
24
  authenticate?: undefined;
@@ -143,8 +59,8 @@ declare const _default: ({
143
59
  };
144
60
  };
145
61
  data?: undefined;
146
- defaultValue?: undefined;
147
62
  reorder?: undefined;
63
+ defaultValue?: undefined;
148
64
  components?: undefined;
149
65
  dataSrc?: undefined;
150
66
  authenticate?: undefined;
@@ -192,9 +108,9 @@ declare const _default: ({
192
108
  data?: undefined;
193
109
  as?: undefined;
194
110
  editor?: undefined;
195
- defaultValue?: undefined;
196
111
  description?: undefined;
197
112
  reorder?: undefined;
113
+ defaultValue?: undefined;
198
114
  components?: undefined;
199
115
  dataSrc?: undefined;
200
116
  authenticate?: undefined;
@@ -303,9 +219,9 @@ declare const _default: ({
303
219
  };
304
220
  as?: undefined;
305
221
  editor?: undefined;
306
- defaultValue?: undefined;
307
222
  description?: undefined;
308
223
  reorder?: undefined;
224
+ defaultValue?: undefined;
309
225
  components?: undefined;
310
226
  skipMerge?: undefined;
311
227
  refreshOn?: undefined;
@@ -340,8 +256,8 @@ declare const _default: ({
340
256
  data?: undefined;
341
257
  as?: undefined;
342
258
  editor?: undefined;
343
- defaultValue?: undefined;
344
259
  reorder?: undefined;
260
+ defaultValue?: undefined;
345
261
  components?: undefined;
346
262
  dataSrc?: undefined;
347
263
  authenticate?: undefined;
@@ -411,9 +327,9 @@ declare const _default: ({
411
327
  };
412
328
  as?: undefined;
413
329
  editor?: undefined;
414
- defaultValue?: undefined;
415
330
  description?: undefined;
416
331
  reorder?: undefined;
332
+ defaultValue?: undefined;
417
333
  components?: undefined;
418
334
  authenticate?: undefined;
419
335
  placeholder?: undefined;
@@ -443,12 +359,12 @@ declare const _default: ({
443
359
  url?: undefined;
444
360
  custom?: undefined;
445
361
  };
446
- conditional?: undefined;
447
362
  as?: undefined;
448
363
  editor?: undefined;
449
- defaultValue?: undefined;
450
364
  description?: undefined;
365
+ conditional?: undefined;
451
366
  reorder?: undefined;
367
+ defaultValue?: undefined;
452
368
  components?: undefined;
453
369
  authenticate?: undefined;
454
370
  valueProperty?: undefined;
@@ -475,12 +391,53 @@ declare const _default: ({
475
391
  placeholder: string;
476
392
  tooltip: string;
477
393
  data?: undefined;
478
- conditional?: undefined;
479
394
  as?: undefined;
480
395
  editor?: undefined;
396
+ description?: undefined;
397
+ conditional?: undefined;
398
+ reorder?: undefined;
481
399
  defaultValue?: undefined;
400
+ components?: undefined;
401
+ dataSrc?: undefined;
402
+ authenticate?: undefined;
403
+ template?: undefined;
404
+ valueProperty?: undefined;
405
+ clearOnHide?: undefined;
406
+ lazyLoad?: undefined;
407
+ skipMerge?: undefined;
408
+ refreshOn?: undefined;
409
+ onSetItems?: undefined;
410
+ onChange?: undefined;
411
+ validate?: undefined;
412
+ delimiter?: undefined;
413
+ requireDecimal?: undefined;
414
+ encrypted?: undefined;
415
+ rows?: undefined;
416
+ mask?: undefined;
417
+ tableView?: undefined;
418
+ alwaysEnabled?: undefined;
419
+ } | {
420
+ type: string;
421
+ input: boolean;
422
+ key: string;
423
+ label: string;
424
+ tooltip: string;
425
+ weight: number;
426
+ conditional: {
427
+ json: {
428
+ '===': (string | {
429
+ var: string;
430
+ })[];
431
+ and?: undefined;
432
+ in?: undefined;
433
+ };
434
+ };
435
+ data?: undefined;
436
+ as?: undefined;
437
+ editor?: undefined;
482
438
  description?: undefined;
483
439
  reorder?: undefined;
440
+ defaultValue?: undefined;
484
441
  components?: undefined;
485
442
  dataSrc?: undefined;
486
443
  authenticate?: undefined;
@@ -492,6 +449,7 @@ declare const _default: ({
492
449
  refreshOn?: undefined;
493
450
  onSetItems?: undefined;
494
451
  onChange?: undefined;
452
+ placeholder?: undefined;
495
453
  validate?: undefined;
496
454
  delimiter?: undefined;
497
455
  requireDecimal?: undefined;
@@ -520,8 +478,8 @@ declare const _default: ({
520
478
  data?: undefined;
521
479
  as?: undefined;
522
480
  editor?: undefined;
523
- defaultValue?: undefined;
524
481
  reorder?: undefined;
482
+ defaultValue?: undefined;
525
483
  components?: undefined;
526
484
  dataSrc?: undefined;
527
485
  authenticate?: undefined;
@@ -668,8 +626,8 @@ declare const _default: ({
668
626
  data?: undefined;
669
627
  as?: undefined;
670
628
  editor?: undefined;
671
- defaultValue?: undefined;
672
629
  reorder?: undefined;
630
+ defaultValue?: undefined;
673
631
  components?: undefined;
674
632
  dataSrc?: undefined;
675
633
  authenticate?: undefined;
@@ -710,9 +668,9 @@ declare const _default: ({
710
668
  };
711
669
  data?: undefined;
712
670
  as?: undefined;
713
- defaultValue?: undefined;
714
671
  description?: undefined;
715
672
  reorder?: undefined;
673
+ defaultValue?: undefined;
716
674
  components?: undefined;
717
675
  dataSrc?: undefined;
718
676
  authenticate?: undefined;
@@ -759,9 +717,9 @@ declare const _default: ({
759
717
  };
760
718
  as?: undefined;
761
719
  editor?: undefined;
762
- defaultValue?: undefined;
763
720
  description?: undefined;
764
721
  reorder?: undefined;
722
+ defaultValue?: undefined;
765
723
  components?: undefined;
766
724
  authenticate?: undefined;
767
725
  template?: undefined;
@@ -831,10 +789,10 @@ declare const _default: ({
831
789
  defaultValue: boolean;
832
790
  tooltip: string;
833
791
  data?: undefined;
834
- conditional?: undefined;
835
792
  as?: undefined;
836
793
  editor?: undefined;
837
794
  description?: undefined;
795
+ conditional?: undefined;
838
796
  reorder?: undefined;
839
797
  components?: undefined;
840
798
  dataSrc?: undefined;
@@ -927,10 +885,10 @@ declare const _default: ({
927
885
  weight: number;
928
886
  tooltip: string;
929
887
  data?: undefined;
930
- conditional?: undefined;
931
888
  as?: undefined;
932
889
  editor?: undefined;
933
890
  description?: undefined;
891
+ conditional?: undefined;
934
892
  reorder?: undefined;
935
893
  components?: undefined;
936
894
  dataSrc?: undefined;
@@ -973,9 +931,9 @@ declare const _default: ({
973
931
  data?: undefined;
974
932
  as?: undefined;
975
933
  editor?: undefined;
976
- defaultValue?: undefined;
977
934
  description?: undefined;
978
935
  reorder?: undefined;
936
+ defaultValue?: undefined;
979
937
  components?: undefined;
980
938
  dataSrc?: undefined;
981
939
  authenticate?: undefined;
@@ -1003,12 +961,12 @@ declare const _default: ({
1003
961
  label: string;
1004
962
  tooltip: string;
1005
963
  data?: undefined;
1006
- conditional?: undefined;
1007
964
  as?: undefined;
1008
965
  editor?: undefined;
1009
- defaultValue?: undefined;
1010
966
  description?: undefined;
967
+ conditional?: undefined;
1011
968
  reorder?: undefined;
969
+ defaultValue?: undefined;
1012
970
  components?: undefined;
1013
971
  dataSrc?: undefined;
1014
972
  authenticate?: undefined;
@@ -1040,8 +998,8 @@ declare const _default: ({
1040
998
  tooltip: string;
1041
999
  defaultValue: {};
1042
1000
  data?: undefined;
1043
- conditional?: undefined;
1044
1001
  description?: undefined;
1002
+ conditional?: undefined;
1045
1003
  reorder?: undefined;
1046
1004
  components?: undefined;
1047
1005
  dataSrc?: undefined;
@@ -1069,16 +1027,16 @@ declare const _default: ({
1069
1027
  onChange(context: any): void;
1070
1028
  data?: undefined;
1071
1029
  type?: undefined;
1030
+ as?: undefined;
1031
+ editor?: undefined;
1072
1032
  weight?: undefined;
1073
1033
  input?: undefined;
1074
1034
  label?: undefined;
1075
1035
  tooltip?: undefined;
1076
- conditional?: undefined;
1077
- as?: undefined;
1078
- editor?: undefined;
1079
- defaultValue?: undefined;
1080
1036
  description?: undefined;
1037
+ conditional?: undefined;
1081
1038
  reorder?: undefined;
1039
+ defaultValue?: undefined;
1082
1040
  components?: undefined;
1083
1041
  dataSrc?: undefined;
1084
1042
  authenticate?: undefined;
@@ -1150,15 +1108,15 @@ declare const _default: ({
1150
1108
  };
1151
1109
  };
1152
1110
  data?: undefined;
1111
+ as?: undefined;
1112
+ editor?: undefined;
1153
1113
  weight?: undefined;
1154
1114
  input?: undefined;
1155
1115
  label?: undefined;
1156
1116
  tooltip?: undefined;
1157
- as?: undefined;
1158
- editor?: undefined;
1159
- defaultValue?: undefined;
1160
1117
  description?: undefined;
1161
1118
  reorder?: undefined;
1119
+ defaultValue?: undefined;
1162
1120
  components?: undefined;
1163
1121
  dataSrc?: undefined;
1164
1122
  authenticate?: undefined;
@@ -1184,16 +1142,16 @@ declare const _default: ({
1184
1142
  onChange(context: any): void;
1185
1143
  data?: undefined;
1186
1144
  type?: undefined;
1145
+ as?: undefined;
1146
+ editor?: undefined;
1187
1147
  weight?: undefined;
1188
1148
  input?: undefined;
1189
1149
  label?: undefined;
1190
1150
  tooltip?: undefined;
1191
- conditional?: undefined;
1192
- as?: undefined;
1193
- editor?: undefined;
1194
- defaultValue?: undefined;
1195
1151
  description?: undefined;
1152
+ conditional?: undefined;
1196
1153
  reorder?: undefined;
1154
+ defaultValue?: undefined;
1197
1155
  components?: undefined;
1198
1156
  dataSrc?: undefined;
1199
1157
  authenticate?: undefined;
@@ -56,42 +56,6 @@ export default [
56
56
  ],
57
57
  },
58
58
  },
59
- {
60
- type: 'textfield',
61
- weight: 10,
62
- input: true,
63
- key: 'indexeddb.database',
64
- label: 'Database name',
65
- tooltip: 'The name of the indexeddb database.',
66
- conditional: {
67
- json: { '===': [{ var: 'data.dataSrc' }, 'indexeddb'] },
68
- },
69
- },
70
- {
71
- type: 'textfield',
72
- input: true,
73
- key: 'indexeddb.table',
74
- label: 'Table name',
75
- weight: 16,
76
- tooltip: 'The name of table in the indexeddb database.',
77
- conditional: {
78
- json: { '===': [{ var: 'data.dataSrc' }, 'indexeddb'] },
79
- }
80
- },
81
- {
82
- type: 'textarea',
83
- as: 'json',
84
- editor: 'ace',
85
- weight: 18,
86
- input: true,
87
- key: 'indexeddb.filter',
88
- label: 'Row Filter',
89
- tooltip: 'Filter table items that match the object.',
90
- defaultValue: {},
91
- conditional: {
92
- json: { '===': [{ var: 'data.dataSrc' }, 'indexeddb'] },
93
- },
94
- },
95
59
  {
96
60
  type: 'textarea',
97
61
  as: 'json',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6061.f2b1042",
3
+ "version": "5.1.0-dev.6064.1c8db05",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {