Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
2 changes: 1 addition & 1 deletion src/components/select/Select.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Select Component', () => {
assert.equal(component.dataValue.value, 'a');
assert.equal(typeof component.dataValue , 'object');
done();
}, 100);
}, 300);
});
});

Expand Down
Loading