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

Panel component not collapsing #1032

Closed
cmorcom opened this issue Nov 21, 2023 · 1 comment
Closed

Panel component not collapsing #1032

cmorcom opened this issue Nov 21, 2023 · 1 comment
Labels

Comments

@cmorcom
Copy link

cmorcom commented Nov 21, 2023

Environment

  • Formio.js version: 5.2.2
  • Frontend framework: Angular
  • Browser: Google Chrome
  • Browser version: 119.0.6045.160

Steps to Reproduce

  1. Add Panel component
  2. In conditional tab, enter custom javascript code, setting collapsed to true when it meets a condition
  3. Save component
  4. Save form
  5. Test form where the condition is met

Expected behavior

If condition is met, it's expected that the panel will be collapsed.

Observed behavior

The panel does not collapse, even if the condition is met.

collapsed is being set to true (as seen in console), but this is not reflected visually.

Example

Custom code:

function collapseSection() {
      if (data && data.example && data.example < 16) {
        component.collapsed = true;
      }
      else {
        component.collapsed = false;
      }
    
    console.log('collapsed:' + component.collapsed);
}

collapseSection();

Console:
image

@cmorcom cmorcom added the bug label Nov 21, 2023
@travist
Copy link
Member

travist commented Jan 9, 2024

It seems you are just changing the JSON of the component and not re-rendering the form after it has been collapsed. Instead to force the component to be collapsed, you will need to get the Panel component and then call the "collapsed" property on the actual component instance and not the JSON.

export class FormRenderComponent {
  @ViewChild(FormioComponent) formioComponent: FormioComponent;
  function collapseSection() {
      const component = this.formioComponent.formio.getComponent('mypanel');
      if (data && data.example && data.example < 16) {
        component.collapsed = true;
      }
      else {
        component.collapsed = false;
      }
  }
}

@travist travist closed this as completed Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants