@formio/js 5.1.0-dev.6067.676f8e2 → 5.1.0-dev.6068.e295b11
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.
- package/dist/formio.form.js +3 -3
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.full.js +3 -3
- package/dist/formio.full.min.js +1 -1
- package/lib/cjs/components/_classes/component/Component.d.ts +6 -2
- package/lib/cjs/components/_classes/component/Component.js +41 -32
- package/lib/cjs/components/form/Form.d.ts +0 -1
- package/lib/cjs/components/form/Form.js +12 -20
- package/lib/cjs/components/survey/Survey.js +1 -1
- package/lib/mjs/components/_classes/component/Component.d.ts +6 -2
- package/lib/mjs/components/_classes/component/Component.js +41 -32
- package/lib/mjs/components/form/Form.d.ts +0 -1
- package/lib/mjs/components/form/Form.js +12 -20
- package/lib/mjs/components/survey/Survey.js +1 -1
- package/package.json +1 -1
@@ -165,6 +165,7 @@ declare class Component extends Element {
|
|
165
165
|
get componentsMap(): object;
|
166
166
|
parentShouldConditionallyClear(): boolean;
|
167
167
|
parentConditionallyHidden(): boolean;
|
168
|
+
parentDefaultHidden(): boolean;
|
168
169
|
set data(value: any);
|
169
170
|
get data(): any;
|
170
171
|
mergeSchema(component?: {}): any;
|
@@ -228,8 +229,11 @@ declare class Component extends Element {
|
|
228
229
|
get visible(): boolean;
|
229
230
|
get logicallyHidden(): any;
|
230
231
|
_logicallyHidden: any;
|
231
|
-
|
232
|
-
|
232
|
+
shouldConditionallyClearOnPristine(): boolean;
|
233
|
+
shouldConditionallyClear(): boolean;
|
234
|
+
_conditionallyClear: boolean | undefined;
|
235
|
+
conditionallyHidden(): boolean;
|
236
|
+
_conditionallyHidden: boolean | undefined;
|
233
237
|
set currentForm(instance: any);
|
234
238
|
get currentForm(): any;
|
235
239
|
_currentForm: any;
|
@@ -461,7 +461,8 @@ class Component extends Element_1.default {
|
|
461
461
|
parentShouldConditionallyClear() {
|
462
462
|
let currentParent = this.parent;
|
463
463
|
while (currentParent) {
|
464
|
-
if (currentParent.
|
464
|
+
if ((currentParent.allowData && currentParent._conditionallyClear) ||
|
465
|
+
(!currentParent.allowData && currentParent._conditionallyHidden)) {
|
465
466
|
return true;
|
466
467
|
}
|
467
468
|
currentParent = currentParent.parent;
|
@@ -471,7 +472,17 @@ class Component extends Element_1.default {
|
|
471
472
|
parentConditionallyHidden() {
|
472
473
|
let currentParent = this.parent;
|
473
474
|
while (currentParent) {
|
474
|
-
if (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) {
|
475
486
|
return true;
|
476
487
|
}
|
477
488
|
currentParent = currentParent.parent;
|
@@ -689,48 +700,46 @@ class Component extends Element_1.default {
|
|
689
700
|
}
|
690
701
|
return this._logicallyHidden;
|
691
702
|
}
|
692
|
-
|
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() {
|
693
709
|
// Skip if this component has clearOnHide set to false.
|
694
710
|
if (this.component.clearOnHide === false) {
|
695
|
-
|
711
|
+
this._conditionallyClear = false;
|
712
|
+
return this._conditionallyClear;
|
696
713
|
}
|
697
714
|
// If the component is logically hidden, then it is conditionally hidden and should clear.
|
698
715
|
if (this.logicallyHidden) {
|
699
|
-
|
716
|
+
this._conditionallyClear = true;
|
717
|
+
return this._conditionallyClear;
|
700
718
|
}
|
701
719
|
// If we have a condition and it is not conditionally visible, the it should conditionally clear.
|
702
|
-
if (this.hasCondition() &&
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
return false;
|
720
|
+
if (this.hasCondition() &&
|
721
|
+
!this.conditionallyVisible() &&
|
722
|
+
(!this.rootPristine || this.shouldConditionallyClearOnPristine())) {
|
723
|
+
this._conditionallyClear = true;
|
724
|
+
return this._conditionallyClear;
|
708
725
|
}
|
709
|
-
|
710
|
-
|
711
|
-
if (this.hasSetValue) {
|
712
|
-
return this.parentShouldConditionallyClear();
|
713
|
-
}
|
714
|
-
// Clear the value if the parent is conditionally hidden.
|
715
|
-
return this.parentConditionallyHidden();
|
726
|
+
this._conditionallyClear = this.hasSetValue ? false : this.parentShouldConditionallyClear();
|
727
|
+
return this._conditionallyClear;
|
716
728
|
}
|
717
|
-
conditionallyHidden(
|
729
|
+
conditionallyHidden() {
|
730
|
+
// If it is logically hidden, then it is conditionally hidden.
|
718
731
|
if (this.logicallyHidden) {
|
719
|
-
|
732
|
+
this._conditionallyHidden = true;
|
733
|
+
return this._conditionallyHidden;
|
720
734
|
}
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
if (!this.conditionallyVisible()) {
|
726
|
-
return true;
|
727
|
-
}
|
728
|
-
if (skipParent) {
|
729
|
-
// Stop recurrsion for the parent checks.
|
730
|
-
return false;
|
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;
|
731
739
|
}
|
732
|
-
//
|
733
|
-
|
740
|
+
// It is conditionally hidden if its parent is conditionally hidden.
|
741
|
+
this._conditionallyHidden = this.parentConditionallyHidden();
|
742
|
+
return this._conditionallyHidden;
|
734
743
|
}
|
735
744
|
get currentForm() {
|
736
745
|
return this._currentForm;
|
@@ -98,7 +98,6 @@ 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;
|
102
101
|
updateSubFormVisibility(): void;
|
103
102
|
/**
|
104
103
|
* Determines if this form is a Nested Wizard
|
@@ -101,6 +101,9 @@ class FormComponent extends Component_1.default {
|
|
101
101
|
}
|
102
102
|
return this.createSubForm();
|
103
103
|
}
|
104
|
+
shouldConditionallyClearOnPristine() {
|
105
|
+
return !this.hasSetValue && super.shouldConditionallyClearOnPristine();
|
106
|
+
}
|
104
107
|
get dataReady() {
|
105
108
|
var _a;
|
106
109
|
return ((_a = this.subForm) === null || _a === void 0 ? void 0 : _a.dataReady) || this.subFormReady || Promise.resolve();
|
@@ -290,11 +293,13 @@ class FormComponent extends Component_1.default {
|
|
290
293
|
}
|
291
294
|
this.subForm.attach(element);
|
292
295
|
this.valueChanged = this.hasSetValue;
|
293
|
-
if (!this.
|
294
|
-
this.
|
295
|
-
|
296
|
-
|
297
|
-
|
296
|
+
if (!this.shouldConditionallyClear()) {
|
297
|
+
if (!this.valueChanged && this.dataValue.state !== 'submitted') {
|
298
|
+
this.setDefaultValue();
|
299
|
+
}
|
300
|
+
else {
|
301
|
+
this.restoreValue();
|
302
|
+
}
|
298
303
|
}
|
299
304
|
}
|
300
305
|
if (!this.builderMode && this.component.modalEdit) {
|
@@ -411,7 +416,7 @@ class FormComponent extends Component_1.default {
|
|
411
416
|
lodash_1.default.assign(componentsMap, formComponentsMap);
|
412
417
|
this.component.components = this.subForm.components.map((comp) => comp.component);
|
413
418
|
this.subForm.on('change', () => {
|
414
|
-
if (this.subForm) {
|
419
|
+
if (this.subForm && !this.shouldConditionallyClear()) {
|
415
420
|
this.dataValue = this.subForm.getValue();
|
416
421
|
this.triggerChange({
|
417
422
|
noEmit: true
|
@@ -679,20 +684,7 @@ class FormComponent extends Component_1.default {
|
|
679
684
|
}
|
680
685
|
}
|
681
686
|
isEmpty(value = this.dataValue) {
|
682
|
-
return value === null || lodash_1.default.isEqual(value, this.emptyValue)
|
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;
|
687
|
+
return value === null || lodash_1.default.isEqual(value, this.emptyValue);
|
696
688
|
}
|
697
689
|
getValue() {
|
698
690
|
if (this.subForm) {
|
@@ -120,7 +120,7 @@ class SurveyComponent extends Field_1.default {
|
|
120
120
|
return this.component.questions.reduce((result, question) => result && Boolean(value[question.value]), true);
|
121
121
|
}
|
122
122
|
getInputName(question) {
|
123
|
-
return `${this.options.name}[${question.value}]
|
123
|
+
return `${this.options.name}[${question.value}]`;
|
124
124
|
}
|
125
125
|
getValueAsString(value, options) {
|
126
126
|
if (options === null || options === void 0 ? void 0 : options.email) {
|
@@ -165,6 +165,7 @@ declare class Component extends Element {
|
|
165
165
|
get componentsMap(): object;
|
166
166
|
parentShouldConditionallyClear(): boolean;
|
167
167
|
parentConditionallyHidden(): boolean;
|
168
|
+
parentDefaultHidden(): boolean;
|
168
169
|
set data(value: any);
|
169
170
|
get data(): any;
|
170
171
|
mergeSchema(component?: {}): any;
|
@@ -228,8 +229,11 @@ declare class Component extends Element {
|
|
228
229
|
get visible(): boolean;
|
229
230
|
get logicallyHidden(): any;
|
230
231
|
_logicallyHidden: any;
|
231
|
-
|
232
|
-
|
232
|
+
shouldConditionallyClearOnPristine(): boolean;
|
233
|
+
shouldConditionallyClear(): boolean;
|
234
|
+
_conditionallyClear: boolean | undefined;
|
235
|
+
conditionallyHidden(): boolean;
|
236
|
+
_conditionallyHidden: boolean | undefined;
|
233
237
|
set currentForm(instance: any);
|
234
238
|
get currentForm(): any;
|
235
239
|
_currentForm: any;
|
@@ -425,7 +425,8 @@ export default class Component extends Element {
|
|
425
425
|
parentShouldConditionallyClear() {
|
426
426
|
let currentParent = this.parent;
|
427
427
|
while (currentParent) {
|
428
|
-
if (currentParent.
|
428
|
+
if ((currentParent.allowData && currentParent._conditionallyClear) ||
|
429
|
+
(!currentParent.allowData && currentParent._conditionallyHidden)) {
|
429
430
|
return true;
|
430
431
|
}
|
431
432
|
currentParent = currentParent.parent;
|
@@ -435,7 +436,17 @@ export default class Component extends Element {
|
|
435
436
|
parentConditionallyHidden() {
|
436
437
|
let currentParent = this.parent;
|
437
438
|
while (currentParent) {
|
438
|
-
if (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) {
|
439
450
|
return true;
|
440
451
|
}
|
441
452
|
currentParent = currentParent.parent;
|
@@ -653,48 +664,46 @@ export default class Component extends Element {
|
|
653
664
|
}
|
654
665
|
return this._logicallyHidden;
|
655
666
|
}
|
656
|
-
|
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() {
|
657
673
|
// Skip if this component has clearOnHide set to false.
|
658
674
|
if (this.component.clearOnHide === false) {
|
659
|
-
|
675
|
+
this._conditionallyClear = false;
|
676
|
+
return this._conditionallyClear;
|
660
677
|
}
|
661
678
|
// If the component is logically hidden, then it is conditionally hidden and should clear.
|
662
679
|
if (this.logicallyHidden) {
|
663
|
-
|
680
|
+
this._conditionallyClear = true;
|
681
|
+
return this._conditionallyClear;
|
664
682
|
}
|
665
683
|
// If we have a condition and it is not conditionally visible, the it should conditionally clear.
|
666
|
-
if (this.hasCondition() &&
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
return false;
|
684
|
+
if (this.hasCondition() &&
|
685
|
+
!this.conditionallyVisible() &&
|
686
|
+
(!this.rootPristine || this.shouldConditionallyClearOnPristine())) {
|
687
|
+
this._conditionallyClear = true;
|
688
|
+
return this._conditionallyClear;
|
672
689
|
}
|
673
|
-
|
674
|
-
|
675
|
-
if (this.hasSetValue) {
|
676
|
-
return this.parentShouldConditionallyClear();
|
677
|
-
}
|
678
|
-
// Clear the value if the parent is conditionally hidden.
|
679
|
-
return this.parentConditionallyHidden();
|
690
|
+
this._conditionallyClear = this.hasSetValue ? false : this.parentShouldConditionallyClear();
|
691
|
+
return this._conditionallyClear;
|
680
692
|
}
|
681
|
-
conditionallyHidden(
|
693
|
+
conditionallyHidden() {
|
694
|
+
// If it is logically hidden, then it is conditionally hidden.
|
682
695
|
if (this.logicallyHidden) {
|
683
|
-
|
696
|
+
this._conditionallyHidden = true;
|
697
|
+
return this._conditionallyHidden;
|
684
698
|
}
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
if (!this.conditionallyVisible()) {
|
690
|
-
return true;
|
691
|
-
}
|
692
|
-
if (skipParent) {
|
693
|
-
// Stop recurrsion for the parent checks.
|
694
|
-
return false;
|
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;
|
695
703
|
}
|
696
|
-
//
|
697
|
-
|
704
|
+
// It is conditionally hidden if its parent is conditionally hidden.
|
705
|
+
this._conditionallyHidden = this.parentConditionallyHidden();
|
706
|
+
return this._conditionallyHidden;
|
698
707
|
}
|
699
708
|
get currentForm() {
|
700
709
|
return this._currentForm;
|
@@ -98,7 +98,6 @@ 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;
|
102
101
|
updateSubFormVisibility(): void;
|
103
102
|
/**
|
104
103
|
* Determines if this form is a Nested Wizard
|
@@ -96,6 +96,9 @@ export default class FormComponent extends Component {
|
|
96
96
|
}
|
97
97
|
return this.createSubForm();
|
98
98
|
}
|
99
|
+
shouldConditionallyClearOnPristine() {
|
100
|
+
return !this.hasSetValue && super.shouldConditionallyClearOnPristine();
|
101
|
+
}
|
99
102
|
get dataReady() {
|
100
103
|
return this.subForm?.dataReady || this.subFormReady || Promise.resolve();
|
101
104
|
}
|
@@ -286,11 +289,13 @@ export default class FormComponent extends Component {
|
|
286
289
|
}
|
287
290
|
this.subForm.attach(element);
|
288
291
|
this.valueChanged = this.hasSetValue;
|
289
|
-
if (!this.
|
290
|
-
this.
|
291
|
-
|
292
|
-
|
293
|
-
|
292
|
+
if (!this.shouldConditionallyClear()) {
|
293
|
+
if (!this.valueChanged && this.dataValue.state !== 'submitted') {
|
294
|
+
this.setDefaultValue();
|
295
|
+
}
|
296
|
+
else {
|
297
|
+
this.restoreValue();
|
298
|
+
}
|
294
299
|
}
|
295
300
|
}
|
296
301
|
if (!this.builderMode && this.component.modalEdit) {
|
@@ -405,7 +410,7 @@ export default class FormComponent extends Component {
|
|
405
410
|
_.assign(componentsMap, formComponentsMap);
|
406
411
|
this.component.components = this.subForm.components.map((comp) => comp.component);
|
407
412
|
this.subForm.on('change', () => {
|
408
|
-
if (this.subForm) {
|
413
|
+
if (this.subForm && !this.shouldConditionallyClear()) {
|
409
414
|
this.dataValue = this.subForm.getValue();
|
410
415
|
this.triggerChange({
|
411
416
|
noEmit: true
|
@@ -668,20 +673,7 @@ export default class FormComponent extends Component {
|
|
668
673
|
}
|
669
674
|
}
|
670
675
|
isEmpty(value = this.dataValue) {
|
671
|
-
return value === null || _.isEqual(value, this.emptyValue)
|
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;
|
676
|
+
return value === null || _.isEqual(value, this.emptyValue);
|
685
677
|
}
|
686
678
|
getValue() {
|
687
679
|
if (this.subForm) {
|
@@ -118,7 +118,7 @@ export default class SurveyComponent extends Field {
|
|
118
118
|
return this.component.questions.reduce((result, question) => result && Boolean(value[question.value]), true);
|
119
119
|
}
|
120
120
|
getInputName(question) {
|
121
|
-
return `${this.options.name}[${question.value}]
|
121
|
+
return `${this.options.name}[${question.value}]`;
|
122
122
|
}
|
123
123
|
getValueAsString(value, options) {
|
124
124
|
if (options?.email) {
|