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-9002: fix issue with conditionally hidden duplicate nested form paths #162

Merged
merged 6 commits into from
Oct 4, 2024

Conversation

brendanbond
Copy link
Contributor

@brendanbond brendanbond commented Oct 3, 2024

Link to Jira Ticket

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

Description

Imagine a parent form which nests two forms - conditionally shown on a parent checkbox - which, in turn, nest the same resource, something like:

Parent Form
    Checkbox (Show Form A)
    Child Form A
        Person Resource
            First Name Textfield
            Last Name Textfield
    Child Form B
        Person Resource
            First Name Textfield
            Last Name Textfield

Normally, we'd expect component pathing to come to our rescue here, i.e. conditionally hidden components would be keyed by absolute path and hidden/cleared/what-have-you'd as expected. However, there is a wrinkle: since we "mask" the paths and data of nested forms in order to ensure that their evaluation context is correct, the pathing for hidden components and nested forms becomes unusable, as one nested form's hidden components will be keyed in the "conditionals" scope identically to another, which means they'll all be hidden/cleared/what-have-you'd. So how do you ensure a child knows its parent is hidden without resorting to pathing?

This PR introduces the concept of "ephermal state," or state that is added as a non-enumerable property to the component JSON in order to facilitate stateful operations during form and submission traversal. For example, rather than performing an ad-hoc traversal of child components to make sure they are hidden, we can simply add an ephermal state value of conditionallyHidden to the component and make sure to pass the component as the parent to subsequent child components.

To enable this concept, this PR:

  • adds registerEphermalState and resetEphermalState methods to utilities;
  • ports logic from eachComponent into eachComponentData to ensure that layout components are passed through to child components as the parent; and
  • reorganizes some utility files and code.

Breaking Changes / Backwards Compatibility

n/a

Dependencies

n/a

How has this PR been tested?

Wrote automated tests and ensured that formiojs, formio, and formio-server tests are passing.

Checklist:

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

…ions, along with supporting refactors and minor linting changes.
@brendanbond brendanbond marked this pull request as draft October 3, 2024 14:55
@brendanbond brendanbond marked this pull request as ready for review October 3, 2024 21:16
Copy link
Member

@travist travist left a comment

Choose a reason for hiding this comment

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

Looks great!

@travist travist merged commit 9c6493c into master Oct 4, 2024
8 checks passed
lane-formio pushed a commit that referenced this pull request Oct 4, 2024
…aths (#162)

* Adds the ability to register ephermal state to component JSON definitions, along with supporting refactors and minor linting changes.

* minor lints

* minor updates

* updates to ephermal properties not in state

* move reset to processOne
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.

2 participants