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-7956: fixed an issue where simple condition based on stringified checkbox value is not executed correctly #5527

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
18 changes: 18 additions & 0 deletions src/Webform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3033,6 +3033,24 @@ describe('Webform tests', function() {
})
.catch(done);
});

it('Should hide field if the checkbox based condition with string value is met', function(done) {
const formElement = document.createElement('div');
const form = new Webform(formElement);
const formCopy = fastCloneDeep(formsWithNewSimpleConditions.form7);

form.setForm(formCopy).then(() => {
const conditionalComponent = form.getComponent('textField');
assert.equal(conditionalComponent.visible, true, 'Component should be conditionally visible');

form.setValue({ data: { checkbox: true } });

setTimeout(() => {
assert.equal(conditionalComponent.visible, false, 'Component should be conditionally hidden');
done();
}, 300);
}).catch((err) => done(err));
});
});

describe('Calculate Value with allowed manual override', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/conditionOperators/IsEqualTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class IsEqualTo extends ConditionOperator {
}

execute({ value, comparedValue, instance, conditionComponentPath }) {
if (value && comparedValue && typeof value !== typeof comparedValue && _.isString(comparedValue)) {
if ((value || value === false) && comparedValue && typeof value !== typeof comparedValue && _.isString(comparedValue)) {
try {
comparedValue = JSON.parse(comparedValue);
}
Expand Down
44 changes: 43 additions & 1 deletion test/forms/formsWithNewSimpleConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,11 +1022,53 @@ const form6 = {
machineName: 'cpxkpoxmfvhivle:selectBoxesCond',
};

const form7 = {
type: 'form',
display: 'form',
components: [
{
label: 'Checkbox',
tableView: false,
key: 'checkbox',
type: 'checkbox',
input: true,
},
{
label: 'Text Field',
applyMaskOn: 'change',
tableView: true,
key: 'textField',
conditional: {
show: true,
conjunction: 'all',
conditions: [
{
component: 'checkbox',
operator: 'isEqual',
value: 'false',
},
],
},
type: 'textfield',
input: true,
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false,
},
],
};

export default {
form1,
form2,
form3,
form4,
form5,
form6
form6,
form7
};
Loading