# Toggle Panel Controller — example configuration

> **Required placement:** Put the Custom Code and native Toggle at the **same layout level**. Recommended: both are sibling controls inside **one Container**. A controller at a different nested level may not work even when its CSS ID and variable binding are correct.
>

```text
Container
├── Custom Code: Toggle Panel Controller
└── Toggle: approval-toggle
```

## Three-panel approval form

| Panel position | Example title | Command value |
| --- | --- | --- |
| First | Requester details | `1` |
| Second | Financial review | `2` |
| Third | Supporting documents | `3` |

Multiple panels: text **`2,3` = expand the second and third panels only**. With five or more panels, text **`1,5` = expand the first and fifth only**. Special commands: **`-1` = expand all; `0` = collapse all**. A fourth panel, if added, uses `4`; further panels use their one-based position through `N`.

## Native Toggle

- Layout: **Classic**.
- CSS ID: `approval-toggle`.
- Keep all existing fields inside their original panels.

## Temporary variable

- Name: `ActivePanelIndex` (example; another meaningful name is allowed).
- Value source: form actions or an expression assignment.
- Values: one integer, numeric text, or comma-separated positive positions. Use a **text-capable** temporary variable for `2,3` and `1,5`.

## New Custom Code control

- Placement: **same layout level as the Toggle**, preferably sibling controls inside the **same Container** on the Approval form; outside the Toggle panels and any hidden container.
- Source: the complete `toggle-panel-controller.tsx` file, entered in **Code editor**.

| Input parameter | Value/binding |
| --- | --- |
| `toggleCssId` | Plain text: `approval-toggle` |
| `activePanelIndex` | Expression selector: **Temp variables → ActivePanelIndex** |

## Single select and button

Single select values: `-1`, `0`, `1`, `2`, `3`, `2,3`. In a form with five panels, also add `4`, `5`, `1,5`. Store each multi-panel value as the complete comma-separated text command.

Button action: **Set variables → Single Value**.

| Setting | Configuration |
| --- | --- |
| Execution Condition | Empty, unless a deliberate Boolean condition is required |
| Variable | Select **Temp variables → ActivePanelIndex** |
| Value | Select the Single select's actual associated form/workflow variable |

The associated Single select variable depends on your form; select it from the editor instead of copying a sample variable ID.

## Initial state

In a form load action, optionally assign `2` to `ActivePanelIndex` to open Financial review on load. Use `-1` to start expanded or `0` to start collapsed. An empty value leaves the native state unchanged.

## Direct command buttons

For separate Expand all / Collapse all buttons, assign constants directly:

| Button | Destination | Value |
| --- | --- | --- |
| Expand all | Temp variables → ActivePanelIndex | `-1` |
| Collapse all | Temp variables → ActivePanelIndex | `0` |
| Review financials | Temp variables → ActivePanelIndex | `2` |
| Review financials and documents | Temp variables → ActivePanelIndex | Text `2,3` |
| Review first and fifth sections (five panels required) | Temp variables → ActivePanelIndex | Text `1,5` |

## Acceptance checks

| Choose, then press button | Expected expanded panels |
| --- | --- |
| `2` | Second only |
| Text `2,3` | Second and third only |
| `-1` | First, second and third |
| `0` | None |
| `3` | Third only |
| `1` | First only |
| `-1` | All three again |
| Text `1,5` in a five-panel form | First and fifth only |
| Text `1,99` when panel 99 does not exist | No changes; no partial application |

After a command, manual clicks remain available. The variable is a command, not live state. Reassigning the same value does not necessarily issue a new command. This is not a Form Action Custom Code step, and it does not submit the form or change business data.
