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-8389: Fix EditGrid with Empty/Is Not Empty conditional logic in there #5612

Closed
Closed
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
31 changes: 31 additions & 0 deletions src/components/editgrid/EditGrid.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
comp13,
comp14,
comp15,
comp16,
withOpenWhenEmptyAndConditions,
compOpenWhenEmpty,
compWithCustomDefaultValue,
Expand Down Expand Up @@ -1561,4 +1562,34 @@ describe('EditGrid Open when Empty', () => {
}, 100);
}).catch(done);
});

it('Hide or show textfield and checkbox components inside of EditGrid conditionally', (done) => {
const formElement = document.createElement('div');
Formio.createForm(formElement, comp16)
.then((form) => {
const editGrid = form.components[0];
editGrid.addRow();
const textField1 = editGrid.getComponent('textField1')[0];
const checkBox1 = editGrid.getComponent('checkbox1')[0];
checkBox1.setValue(true);
textField1.setValue('Some value');

setTimeout(() => {
const textField2 = editGrid.getComponent('textField2')[0];
const checkBox2 = editGrid.getComponent('checkbox2')[0];
assert.equal(textField2.visible, false);
assert.equal(checkBox2.visible, false);
textField1.setValue('');
checkBox1.setValue(false);

setTimeout(() => {
const textField2 = editGrid.getComponent('textField2')[0];
const checkBox2 = editGrid.getComponent('checkbox2')[0];
assert.equal(textField2.visible, true);
assert.equal(checkBox2.visible, true);
done();
}, 300);
}, 300);
}).catch(done);
});
});
78 changes: 78 additions & 0 deletions src/components/editgrid/fixtures/comp16.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
export default {
type: 'form',
display: 'form',
components: [
{
label: 'Edit Grid',
tableView: false,
rowDrafts: false,
key: 'editGrid',
type: 'editgrid',
displayAsTable: false,
input: true,
components: [
{
label: 'Text Field',
applyMaskOn: 'change',
tableView: true,
key: 'textField1',
type: 'textfield',
input: true
},
{
label: 'Text Field',
applyMaskOn: 'change',
tableView: true,
key: 'textField2',
conditional: {
show: true,
conjunction: 'all',
conditions: [
{
component: 'editGrid.textField1',
operator: 'isEmpty'
}
]
},
type: 'textfield',
input: true
},
{
label: 'Checkbox',
tableView: false,
defaultValue: false,
key: 'checkbox1',
type: 'checkbox',
input: true
},
{
label: 'Checkbox',
tableView: false,
defaultValue: false,
key: 'checkbox2',
conditional: {
show: true,
conjunction: 'all',
conditions: [
{
component: 'editGrid.checkbox1',
operator: 'isEqual',
value: false
}
]
},
type: 'checkbox',
input: true
}
]
},
{
type: 'button',
label: 'Submit',
key: 'submit',
disableOnInvalid: true,
input: true,
tableView: false
}
],
};
3 changes: 2 additions & 1 deletion src/components/editgrid/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import comp12 from './comp12';
import comp13 from './comp13';
import comp14 from './comp14';
import comp15 from './comp15';
import comp16 from './comp16';
import withOpenWhenEmptyAndConditions from './comp-with-conditions-and-openWhenEmpty';
import compOpenWhenEmpty from './comp-openWhenEmpty';
import compWithCustomDefaultValue from './comp-with-custom-default-value';
export { comp1, comp2, comp3, comp10, comp11, comp12, comp13, comp14, comp15, comp4, comp5, comp6, comp7, comp8, comp9, compOpenWhenEmpty, withOpenWhenEmptyAndConditions, compWithCustomDefaultValue };
export { comp1, comp2, comp3, comp10, comp11, comp12, comp13, comp14, comp15, comp16, comp4, comp5, comp6, comp7, comp8, comp9, compOpenWhenEmpty, withOpenWhenEmptyAndConditions, compWithCustomDefaultValue };
2 changes: 1 addition & 1 deletion src/utils/conditionOperators/IsEmptyValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class IsEmptyValue extends ConditionOperator {

if (instance && instance.root) {
const conditionTriggerComponent = instance.root.getComponent(conditionComponentPath);
return conditionTriggerComponent ? conditionTriggerComponent.isEmpty() : isEmptyValue;
return conditionTriggerComponent?.isEmpty ? conditionTriggerComponent.isEmpty() : isEmptyValue;
}

return isEmptyValue;
Expand Down
Loading