Skip to content

Commit

Permalink
FIO-7547: Container hidden with conditional logic still appears in su…
Browse files Browse the repository at this point in the history
…bmission (#5401)

* FIO-7547: Container hidden with conditional logic still appears in submission

* Fixed tests
  • Loading branch information
alexandraRamanenka authored and lane-formio committed Nov 22, 2023
1 parent 2cd8c2e commit d11c5c7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/_classes/nested/NestedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ export default class NestedComponent extends Field {
clearOnHide(show) {
super.clearOnHide(show);
if (this.component.clearOnHide) {
if (this.allowData && !this.hasValue()) {
if (this.allowData && !this.hasValue() && !(this.options.server && !this.visible)) {
this.dataValue = this.defaultValue;
}
if (this.hasValue()) {
Expand Down
22 changes: 21 additions & 1 deletion src/components/container/Container.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import ContainerComponent from './Container';
import {
comp1,
comp2,
comp3
comp3,
comp4,
} from './fixtures';

import Formio from '../../Formio';
Expand Down Expand Up @@ -77,4 +78,23 @@ describe('Container Component', () => {
}, 100);
}).catch(done);
});

it('Should not set the default value when clearOnHide during the server-side validation', (done) => {
const form = _.cloneDeep(comp4);
const element = document.createElement('div');

Formio.createForm(element, form, { server: true, noDefaults: true }).then(form => {
form.setValue({ data: { checkbox: false } }, {
sanitize: true,
}, true);

form.checkConditions();
form.clearOnHide();

setTimeout(() => {
assert.deepEqual(form._data, { checkbox: false }, 'Should not add Container\'s key');
done();
}, 200);
}).catch(done);
});
});
43 changes: 43 additions & 0 deletions src/components/container/fixtures/comp4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export default {
type: 'form',
display: 'form',
components: [
{
label: 'Checkbox',
tableView: false,
key: 'checkbox',
type: 'checkbox',
input: true,
},
{
label: 'Container',
tableView: false,
key: 'container',
conditional: {
show: true,
when: 'checkbox',
eq: 'true',
},
type: 'container',
input: true,
components: [
{
label: 'Text Field',
applyMaskOn: 'change',
tableView: true,
key: 'textField',
type: 'textfield',
input: true,
},
],
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false,
},
],
};
1 change: 1 addition & 0 deletions src/components/container/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export comp1 from './comp1';
export comp2 from './comp2';
export comp3 from './comp3';
export comp4 from './comp4';
2 changes: 1 addition & 1 deletion src/components/select/Select.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Select Component', () => {
assert.equal(component.dataValue.value, 'a');
assert.equal(typeof component.dataValue , 'object');
done();
}, 100);
}, 300);
});
});

Expand Down

0 comments on commit d11c5c7

Please sign in to comment.