Jump to content

Help:DropDown

From RiskiPedia

Help:DropDown

The `<dropdown>` tag creates an interactive dropdown menu that displays data from a RiskData table, allowing you to select a row. When a row is chosen the other columns from the RiskData table are set as variables and any RiskModels that use them are re-calculated and RiskDisplay elements are updated.

Syntax

The `<dropdown>` tag supports these attributes:

  • `table`: (Required) The name of the RiskData table to display.
  • `title`: (Optional) The label shown when no item is selected. Defaults to "Select".
  • `label_column`: (Optional) The table column to use as the display label. Defaults to the first column.
  • `default`: (Optional) Which item is selected by default (e.g. default=Apple)
  • `default-index`: (Optional) The zero-based index of the default selected item (takes precedence over `default`).

Basic syntax:

<dropdown table="TableName" title="Choose an option" label_column="ColumnName" default="DefaultLabel" default-index="0" />

Examples

Basic Dropdown

Display a dropdown using the "Fruits" table, showing the "Name" column:

<dropdown table="Fruits" title="Select a fruit" label_column="Name" />

This lists values like "Apple", "Banana", and "Orange" if they exist in the "Name" column.

Dropdown with Default Selection

Set "Banana" as the default selected item:

<dropdown table="Fruits" title="Select a fruit" label_column="Name" default="Banana" />

Dropdown with Default Index

Select the second item (index 1) by default:

<dropdown table="Fruits" title="Select a fruit" label_column="Name" default-index="1" />

Fully-Qualified Table Name

For a table on a subpage (e.g., "Data:Fruits" under "Market"):

<dropdown table="Market/Data:Fruits" title="Select a fruit" label_column="Name" />

Let the user select which data table to use

You might let a user choice select which data table to use by putting a dropdown inside a riskdisplay. For example, if there are different tables for snowboarders versus skiiers you might structure your page like this:

<riskdata table="SnowboardOrSki" columns="choice|data_table" hidden>
Ski|ski_risks
Snowboard|snowboard_risks
</riskdata>

<dropdown table="SnowboardOrSki" />
<riskdisplay><dropdown table={data_table}/></riskdisplay>

Notes

  • The `table` attribute can be a simple name (e.g., "Fruits"), a page-specific name (e.g., "Market:Fruits"), or a subpage (e.g., "Market/Data:Fruits"). The system searches the current page and its "Data/" subpage if needed.
  • If the table is empty or not found, an error message will appear (e.g., "dropdown: empty RiskData table Fruits").
  • Ensure `label_column` matches a column in the table, or an error will list valid columns.
  • The dropdown's width adjusts automatically based on the longest label or title.

Troubleshooting

  • **Error: "dropdown: missing table attribute"** – Ensure the `table` attribute is included.
  • **Error: "dropdown: cannot find RiskData table"** – Verify the table exists and the name is correct (check for typos or incorrect page/subpage paths).
  • **Error: "dropdown: no column named X"** – Confirm `label_column` matches a column in the table.
  • **Dropdown appears empty** – Check that the RiskData table contains data and is properly formatted.