Skip to content

Commit

Permalink
Merge pull request #120 from formio/fio-8537-clearOnHide-false
Browse files Browse the repository at this point in the history
fixing child components being displayed when they should be removed when clearOnHide is set
  • Loading branch information
lane-formio committed Jul 30, 2024
1 parent 1778a83 commit 22a14cd
Show file tree
Hide file tree
Showing 3 changed files with 363 additions and 14 deletions.
360 changes: 360 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,366 @@ describe('Process Tests', () => {
expect((context.scope as ValidationScope).errors).to.have.length(1);
});
});
it('Should not return fields from conditionally hidden containers', async () => {
const form = {
display: 'form',
"components": [
{
"title": "__information_on_the_appointee",
"theme": "primary",
"collapsible": false,
"key": "HeadingNestedFormCandidates",
"type": "panel",
"label": "Appointees",
"input": false,
"tableView": false,
"components": [
{
"label": "Appointees",
"hideLabel": true,
"tableView": false,

"addAnother": "__add_appointee",
"modal": true,
"saveRow": "Close",
"rowDrafts": true,
"key": "candidates",
"type": "editgrid",
"displayAsTable": false,
"input": true,
"components": [
{
"label": "Appointee",
"tableView": false,
"key": "candidate",
"type": "container",
"input": true,
"components": [
{
"label": "Data",
"tableView": false,
"key": "data",
"type": "container",
"input": true,
"components": [
{
"label": "Tabs",
"components": [
{
"label": "__6_time_commitment",
"key": "section6tab",
"components": [
{
"label": "Section 6",
"tableView": false,
"clearOnHide": true,
"validateWhenHidden": false,
"key": "section6",
"properties": {
"clearHiddenOnSave": "true"
},
"customConditional": "show = false;",
"type": "container",
"input": true,
"components": [
{
"title": "__6_dash_time_commitment",
"theme": "primary",
"collapsible": false,
"key": "heading6",
"type": "panel",
"label": "Time Commitment",
"input": false,
"tableView": false,
"components": [
{
"label": "__a_information_to_be_provided_by_the_supervised_entity_the",
"description": "__ul_li_see_the_report_on_declared_time_commitment_of",
"autoExpand": false,
"tableView": true,
"validate": {
"required": true
},
"key": "entityExpectedTimeCommit",
"type": "textarea",
"input": true
},
{
"label": "c",
"tableView": false,
"key": "c",
"type": "container",
"input": true,
"components": []
},
{
"label": "__d_list_of_executive_and_non_executive_directorships_and_other",
"description": "__for_each_directorship_or_other_activity_a_separate_row_needs",
"tableView": false,
"addAnother": "__add_another",
"validate": {
"required": true
},
"rowDrafts": false,
"key": "d",
"type": "editgrid",
"input": true,
"components": []
}
]
}
]
}
]
}
],
"key": "tabs1",
"type": "tabs",
"input": false,
"tableView": false
}
]
}
]
}
]
}
]
},
{
"label": "Submit",
"action": "saveState",
"showValidations": false,
"tableView": false,
"key": "submit",
"type": "button",
"input": true,
"state": "draft"
}
],

};
const submission = {
"data": {
"candidates": [
{
"candidate": {
"data": {
"section6": {
"c": {},
"d": []
}
}
}
}
],
"submit": true
}
};

const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
console.log(JSON.stringify(context.data, null, 2))
expect(context.data).to.deep.equal({
candidates:[{candidate:{data:{}}}],
submit: true

});

})
it('Should not return fields from conditionally hidden containers, clearOnHide = false', async () => {

const TestForm45588WithClearOnHideFalse = {
display: 'form',
"components": [
{
"title": "__information_on_the_appointee",
"theme": "primary",
"collapsible": false,
"key": "HeadingNestedFormCandidates",
"type": "panel",
"label": "Appointees",
"input": false,
"tableView": false,
"components": [
{
"label": "Appointees",
"hideLabel": true,
"tableView": false,

"addAnother": "__add_appointee",
"modal": true,
"saveRow": "Close",
"rowDrafts": true,
"key": "candidates",
"type": "editgrid",
"displayAsTable": false,
"input": true,
"components": [
{
"label": "Appointee",
"tableView": false,
"key": "candidate",
"type": "container",
"input": true,
"components": [
{
"label": "Data",
"tableView": false,
"key": "data",
"type": "container",
"input": true,
"components": [
{
"label": "Tabs",
"components": [
{
"label": "__6_time_commitment",
"key": "section6tab",
"components": [
{
"label": "Section 6",
"tableView": false,
"clearOnHide": false,
"validateWhenHidden": false,
"key": "section6",
"properties": {
"clearHiddenOnSave": "true"
},
"customConditional": "show = false;",
"type": "container",
"input": true,
"components": [
{
"title": "__6_dash_time_commitment",
"theme": "primary",
"collapsible": false,
"key": "heading6",
"type": "panel",
"label": "Time Commitment",
"input": false,
"tableView": false,
"components": [
{
"label": "__a_information_to_be_provided_by_the_supervised_entity_the",
"description": "__ul_li_see_the_report_on_declared_time_commitment_of",
"autoExpand": false,
"tableView": true,
"validate": {
"required": true
},
"key": "entityExpectedTimeCommit",
"type": "textarea",
"input": true
},
{
"label": "c",
"tableView": false,
"key": "c",
"type": "container",
"input": true,
"components": []
},
{
"label": "__d_list_of_executive_and_non_executive_directorships_and_other",
"description": "__for_each_directorship_or_other_activity_a_separate_row_needs",
"tableView": false,
"addAnother": "__add_another",
"validate": {
"required": true
},
"rowDrafts": false,
"key": "d",
"type": "editgrid",
"input": true,
"components": []
}
]
}
]
}
]
}
],
"key": "tabs1",
"type": "tabs",
"input": false,
"tableView": false
}
]
}
]
}
]
}
]
},
{
"label": "Submit",
"action": "saveState",
"showValidations": false,
"tableView": false,
"key": "submit",
"type": "button",
"input": true,
"state": "draft"
}
],

};

const submission = {
"data": {
"candidates": [
{
"candidate": {
"data": {
"section6": {
"c": {},
"d": []
}
}
}
}
],
"submit": true
}
};

const context = {
form: TestForm45588WithClearOnHideFalse,
submission,
data: submission.data,
components: TestForm45588WithClearOnHideFalse.components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};
processSync(context);
context.processors = ProcessTargets.evaluator;
processSync(context);
console.log(JSON.stringify(context.data, null, 2))
expect(context.data).to.deep.equal({
candidates:[{candidate:{data:{section6:{}}}}],
submit: true

});
})

describe('For EditGrid:', () => {
const components = [
{
Expand Down
3 changes: 2 additions & 1 deletion src/process/clearHidden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export const clearHiddenProcess: ProcessorFnSync<ClearHiddenScope> = (context) =
if (!scope.clearHidden) {
scope.clearHidden = {};
}
//conditional path is a partial path, check to see if in the path
const conditionallyHidden = (scope as ConditionsScope).conditionals?.find((cond) => {
return cond.path === path;
return path.includes(cond.path);
});
if (
conditionallyHidden?.conditionallyHidden &&
Expand Down
Loading

0 comments on commit 22a14cd

Please sign in to comment.