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

fixing child components being displayed when they should be removed when clearOnHide is set #120

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

johnformio
Copy link
Contributor

Link to Jira Ticket

https://formio.atlassian.net/browse/FIO-8537

Description

The issue was that fields that should have been hidden on the submission were

What changed?

two things changed:

  1. in the conditionalProcess function there was a check to see if clearOnHide was checked before setting the conditional fields in the context scope. This was removed.
  2. In the clearHiddenProcess function, the path in the conditional scope entries were checking the complete path of the component to determine if the submission data should be removed. However, the path being set in scope conditional array is a relative path from the parent, and therefore skipped. The change was to do a partial match on the conditional path to see if it should be omitted.

Breaking Changes / Backwards Compatibility

Use this section to describe any potentially breaking changes this PR introduces or any effects this PR might have on backwards compatibility

Dependencies

None

How has this PR been tested?

unit tests

Use this section to describe how you tested your changes; if you haven't included automated tests, justify your reasoning

Checklist:

  • [ x] I have completed the above PR template
  • [x ] I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • [x ] My changes generate no new warnings
  • My changes include tests that prove my fix is effective (or that my feature works as intended)
  • [ x] New and existing unit/integration tests pass locally with my changes
  • Any dependent changes have corresponding PRs that are listed above

Comment on lines -15 to -23
const skipOnServer = (context: ConditionsContext): boolean => {
const { component, config } = context;
const clearOnHide = component.hasOwnProperty('clearOnHide') ? component.clearOnHide : true;
if (config?.server && !clearOnHide) {
// No need to run conditionals on server unless clearOnHide is set.
return true;
}
return false;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer used

Comment on lines +103 to 104
// the path set here is not the absolute path, but the path relative to the parent component
scope.conditionals?.push({ path: getComponentPath(comp, compPath), conditionallyHidden: true });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sets a partial path to the parent <parent-key>.<field-key> not an absolute path

const conditionallyHidden = (scope as ConditionsScope).conditionals?.find((cond) => {
return cond.path === path;
return path.includes(cond.path);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the path set in the conditionals is partial, relaxing the check from exact match to component path contains the conditional path

Copy link
Contributor

@brendanbond brendanbond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@lane-formio lane-formio merged commit 4706261 into master Jul 18, 2024
6 checks passed
lane-formio added a commit that referenced this pull request Jul 30, 2024
fixing child components being displayed when they should be removed when clearOnHide is set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants