Skip to content

Commit

Permalink
FIO-8626: updated conditionally hidden logic (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-formio authored and lane-formio committed Sep 6, 2024
1 parent 89b5d49 commit 9340ab7
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
81 changes: 80 additions & 1 deletion src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2701,6 +2701,85 @@ describe('Process Tests', () => {
});
});

it('Should include submission data for logically visible fields', async () => {
const form = {
display: 'form',
components: [
{
type: 'textfield',
key: 'textField',
label: 'Text Field',
input: true,
},
{
type: 'textarea',
key: 'textArea',
label: 'Text Area',
input: true,
hidden: true,
logic: [
{
name: 'Show When Not Empty',
trigger: {
type: 'simple' as const,
simple: {
show: true,
conjunction: 'all',
conditions: [
{
component: 'textField',
operator: 'isNotEmpty',
},
],
},
},
actions: [
{
name: 'Show',
type: 'property' as const,
property: {
label: 'Hidden',
value: 'hidden',
type: 'boolean' as const,
},
state: false,
},
],
},
],
},
],
};

const submission = {
data: {
textField: 'not empty',
textArea: 'should be conditionally visible',
},
};

const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.evaluator,
scope: {},
config: {
server: true,
},
};
processSync(context);
expect((context.scope as any).conditionals).to.deep.equal([{
path: 'textArea',
conditionallyHidden: false,
}]);
expect(context.data).to.deep.equal({
textArea: 'should be conditionally visible',
textField: 'not empty',
});
});

it('Should not filter a simple datamap compoennt', async () => {
const form = {
display: 'form',
Expand Down Expand Up @@ -2750,7 +2829,7 @@ describe('Process Tests', () => {
key2: "value2"
}
});
})
});

describe('Required component validation in nested form in DataGrid/EditGrid', () => {
const nestedForm = {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ export function setActionBooleanProperty(context: LogicContext, action: LogicAct
if (currentValue !== newValue) {
set(component, property, newValue === 'true');

// If this is "logic" forcing a component to be hidden, then we will set the "conditionallyHidden"
// If this is "logic" forcing a component to set hidden property, then we will set the "conditionallyHidden"
// flag which will trigger the clearOnHide functionality.
if (
property === 'hidden' &&
component.hidden &&
path
) {
if (!(scope as ConditionsScope).conditionals) {
Expand Down

0 comments on commit 9340ab7

Please sign in to comment.