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
  • Loading branch information
alexandraRamanenka committed Nov 10, 2023
1 parent 38f4d53 commit 75718e4
Show file tree
Hide file tree
Showing 4 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 @@ -617,7 +617,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,
},
],
};
3 changes: 2 additions & 1 deletion src/components/container/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import comp1 from './comp1';
import comp2 from './comp2';
import comp3 from './comp3';
export { comp1, comp2, comp3 };
import comp4 from './comp4';
export { comp1, comp2, comp3, comp4 };

0 comments on commit 75718e4

Please sign in to comment.