Skip to content

Commit

Permalink
FIO-7595 fixed incorrect value for conditionally hidden Checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaKurban committed May 13, 2024
1 parent eeaff43 commit b3f7e58
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
13 changes: 2 additions & 11 deletions src/components/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,8 @@ export default class CheckBoxComponent extends Field {
}

setValue(value, flags = {}) {
if (
this.setCheckedState(value) !== undefined ||
(!this.input && value !== undefined && (this.visible || this.conditionallyVisible() || !this.component.clearOnHide))
) {
const changed = this.updateValue(value, flags);
if (this.isHtmlRenderMode() && flags && flags.fromSubmission && changed) {
this.redraw();
}
return changed;
}
return false;
this.setCheckedState(value);
return super.setValue(value, flags);
}

getValueAsString(value) {
Expand Down
26 changes: 25 additions & 1 deletion src/components/checkbox/Checkbox.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
customDefaultComponent,
comp2,
comp3,
comp4
comp4,
comp5
} from './fixtures';

describe('Checkbox Component', () => {
Expand Down Expand Up @@ -91,4 +92,27 @@ describe('Checkbox Component', () => {
}, 300);
}).catch((err) => done(err));
});

it('Should set the value for the checkbox if it set before the component from checbox`s condition', (done) => {
const form = _.cloneDeep(comp5);
const element = document.createElement('div');
const data = {
textField: 'test',
checkboxBefore: true,
checkboxAfter: true
};
Formio.createForm(element, form).then(form => {
form.setValue({ data }, { sanitize: true });
const checkboxBefore = form.getComponent('checkboxBefore');
const checkboxAfter = form.getComponent('checkboxAfter');
setTimeout(() => {
const inputBefore = Harness.testElements(checkboxBefore, 'input[type="checkbox"]', 1)[0];
assert.equal(inputBefore.checked, true);
const inputAfter = Harness.testElements(checkboxAfter, 'input[type="checkbox"]', 1)[0];
assert.equal(inputAfter.checked, true);
assert.deepEqual(form.data, data);
done();
}, 300);
}).catch((err) => done(err));
});
});
53 changes: 53 additions & 0 deletions src/components/checkbox/fixtures/comp5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export default {
title: '7595',
name: '7595',
path: '7595',
type: 'form',
display: 'form',
components:[
{
label: 'Checkbox',
tableView: false,
validateWhenHidden: false,
key: 'checkboxBefore',
conditional: {
show: true,
conjunction: 'all',
conditions: [
{
component: 'textField',
operator: 'isNotEmpty'
}
]
},
type: 'checkbox',
input: true
},
{
label: 'Text Field',
applyMaskOn: 'change',
tableView: true,
key: 'textField',
type: 'textfield',
input: true
},
{
label: 'Checkbox',
tableView: false,
validateWhenHidden: false,
key: 'checkboxAfter',
conditional: {
show: true,
conjunction: 'all',
conditions: [
{
component: 'textField',
operator: 'isNotEmpty'
}
]
},
type: 'checkbox',
input: true
},
]
};
3 changes: 2 additions & 1 deletion src/components/checkbox/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import customDefaultComponent from './customDefaultComponent';
import comp2 from './comp2';
import comp3 from './comp3';
import comp4 from './comp4';
export { comp1, comp2, comp3, comp4, customDefaultComponent };
import comp5 from './comp5';
export { comp1, comp2, comp3, comp4, comp5, customDefaultComponent };

0 comments on commit b3f7e58

Please sign in to comment.