> ## Documentation Index
> Fetch the complete documentation index at: https://calcs.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Lookup Toggle

> Guide to implementing toggle widgets for binary true/false choices in calculator templates

## Widget Core Function

**UI Experience:** Toggle true/false interface for the user\
**Data Organization:** Provides users with exactly two choices to select from, storing the selected data for use in other widgets.

## Key Features

* Simple binary choice interface (Yes/No, True/False, On/Off)
* Clean, intuitive user experience for boolean decisions
* Stores selection as index (0 or 1) for use in calculations
* Supports custom labels for both toggle states

## Video Tutorial

<Card title="Create a Toggle" icon="video">
  [Watch Tutorial](https://www.loom.com/share/b46d5d92c0d6421babf8546864b85902)
  Learn how to create and configure toggle widgets step by step
</Card>

## Visual Presentation

<Info>
  The toggle widget interface provides a simple binary choice (Yes/No, True/False) displayed as radio buttons.
</Info>

## Configuration

### Example Code

```json theme={null}
{
  "type": "sheetTemplateWidgets",
  "attributes": {
    "type": "lookup",
    "label": "Seismic Analysis Required",
    "symbol": "SW_{flag}",
    "defaultValue": "0",
    "visibleIf": "",
    "enableAutosize": false,
    "radioListDisplay": true,
    "dataColumns": [
      {
        "label": "Option",
        "key": "option",
        "type": "string"
      }
    ],
    "dataTable": [
      ["No"],
      ["Yes"]
    ],
    "referenceId": "seismic_analysis_toggle",
    "references": "AS 1170.4",
    "description": "Specify if seismic analysis is required",
    "authorNotes": "Toggle for enabling seismic analysis calculations",
    "referenceImage": ""
  }
}
```

### Configuration Parameters

<ResponseField name="type" type="string" required>
  Set to "lookup" to define the widget type
</ResponseField>

<ResponseField name="radioListDisplay" type="boolean" required>
  Set to `true` for toggle widgets to display as radio buttons instead of dropdown
</ResponseField>

<ResponseField name="dataColumns" type="array" required>
  Simple array with one column definition for the toggle options
</ResponseField>

<ResponseField name="dataTable" type="matrix" required>
  Two-row matrix with the toggle options. Typically \["No"] and \["Yes"] or \["False"] and \["True"]
</ResponseField>

<ResponseField name="enableAutosize" type="boolean" default="false">
  Should be set to `false` for toggle widgets as autosize is not applicable
</ResponseField>

## Common Toggle Patterns

### Yes/No Toggle

```json theme={null}
"dataTable": [
  ["No"],
  ["Yes"]
]
```

### True/False Toggle

```json theme={null}
"dataTable": [
  ["False"],
  ["True"]
]
```

### On/Off Toggle

```json theme={null}
"dataTable": [
  ["Off"],
  ["On"]
]
```

### Custom Labels

```json theme={null}
"dataTable": [
  ["Not Required"],
  ["Required"]
]
```

## Examples from Current Calculators

| Reference ID      | Calculator Link                                                                                                                             |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| lookup (SW\_flag) | [Steel Beam Calculator](https://calcs.com/organisation/2ad7e5c6-8d23-416d-acb1-5487dc65150a/templates/6d7fc7ed-f6f7-4392-822b-cdee58bab93b) |

## Usage in Calculations

Toggle widgets return index values (0 or 1) that can be used in boolean logic:

### Conditional Logic Examples

```javascript theme={null}
// Direct boolean check
if (@seismic_analysis_toggle == 1) {
  // Seismic analysis is required
  seismic_factor = 1.0
} else {
  // No seismic analysis
  seismic_factor = 0.0
}

// Using in equation widgets
seismic_load = @base_load * (@seismic_analysis_toggle == 1 ? @seismic_factor : 0)
```

### Visibility Control

```javascript theme={null}
// Show/hide widgets based on toggle state
"visibleIf": "@seismic_analysis_toggle == 1"
```

## Best Practices

1. **Clear Labels**: Use descriptive labels that make the choice obvious to users
   * Good: "Yes" / "No"
   * Good: "Required" / "Not Required"
   * Avoid: "True" / "False" (less user-friendly)

2. **Default Values**:
   * Set `defaultValue: "0"` for the safer/more conservative option
   * Consider which choice users will select most often

3. **Boolean Logic**: Remember that toggles return indices (0, 1), not boolean values
   * Use `== 1` for "true" checks
   * Use `== 0` for "false" checks

4. **Conditional Visibility**: Use toggles to control visibility of related widgets
   ```json theme={null}
   "visibleIf": "@my_toggle == 1"
   ```

5. **Documentation**: Include clear author notes explaining what each toggle state represents

## Integration Patterns

### Controlling Widget Visibility

```json theme={null}
{
  "type": "input",
  "attributes": {
    "label": "Seismic Load Factor",
    "visibleIf": "@seismic_analysis_toggle == 1",
    "referenceId": "seismic_factor"
  }
}
```

### Conditional Calculations

```json theme={null}
{
  "type": "computed",
  "attributes": {
    "label": "Total Load",
    "equation": [
      {
        "condition": "@seismic_analysis_toggle == 1",
        "result": "@dead_load + @live_load + @seismic_load"
      },
      {
        "condition": "@default",
        "result": "@dead_load + @live_load"
      }
    ],
    "referenceId": "total_load"
  }
}
```

## Troubleshooting

<Warning>
  **Common Issues:**

  * Forgetting to set `radioListDisplay: true` (widget will appear as dropdown instead of toggle)
  * Using boolean values instead of string arrays in dataTable
  * Comparing toggle values as booleans instead of indices (0, 1)
</Warning>

<Info>
  **Remember:** Toggle widgets are implemented as lookup widgets with exactly two options and radio button display enabled. This provides the clean toggle interface while maintaining the flexibility of the lookup widget system.
</Info>
