{options:group:selected}

Description

Builds the HTML option elements for a select dropdown. The first parameter is the source list of choices; the second marks which choice is pre-selected. The source can be a constants group id (the choices come from that group), a JSON array of plain values like [1,2,5,7], or a JSON array of value-label pairs like [[1,"January"],[2,"Feb"]] where the first item of each pair is the option value and the second is its visible label. With a plain-value array the option carries no value attribute, so the value equals the visible text. The selected parameter accepts a single value or, for a multiple select, a JSON array of values such as ["7","8"]; every matching option gets the selected attribute. Place the result inside your own select element. An unknown group or an empty array produces no output. Pairs nicely with the sequence command, which can generate the value list (for example a range of years).

Parameters

group required

The source list of choices. Either a constants group id (options come from that group, value then label per constant), or a JSON array. A plain-value array like [1,2,5,7] makes each value its own visible text with no value attribute; a value-label array like [[1,"January"],[2,"Feb"]] sets the option value from the first item of each pair and the visible label from the second. An unknown group or an empty array produces no output.

selected optional

The value (or values) to mark as pre-selected. A single value selects one option; a JSON array like ["7","8"] selects several at once, for a multiple select. Every option whose value matches gets the selected attribute. Omit it to leave all options unselected.

Examples

virtual{options:{sequence:num:1998:2001}:2000}
Expected(options 1998 1999 2000 2001; 2000 selected)
Actual
The sequence command returns a JSON array of values, which feeds straight into options. Here it makes a year picker from 1998 to 2001 with 2000 pre-selected.
test[{options:[]:7}]
Expected[]
Actual[]
An empty JSON array produces no option elements at all. The surrounding brackets show the result is the empty string.
virtual<select name="month">{options:[[1,"Jan"],[2,"Feb"],[3,"Mar"]]:2}</select>
Expected(a select named month holding three month options, Feb selected)
Actual
The command only emits the option elements; you wrap them in your own select. This is the typical real-world use: a named dropdown with the current value pre-selected.
virtual{options:["red","blue","green"]:blue}
Expected(options red, blue selected, green)
Actual
Plain values work for text too. Here each colour is its own option value and label, and blue is pre-selected.
virtual{options:AA_Core_Bins:1}
Expected(one option per constant in the group, the value 1 option selected)
When the first parameter is a constants group id rather than a JSON array, the choices come from that group: each constant's value is the option value and its name is the label. selected=1 marks the matching option. The output depends on which constant groups exist on your install.
virtual{options:[1,2,5,7]:7}
Expected(four options 1 2 5 7; the 7 option carries selected)
Actual
A JSON array of plain values. Each value becomes both the option value and its visible text (no value attribute is written). The second parameter, 7, pre-selects that option.
virtual{options:[[1,"Jan"],[7,"Jul"],[8,"Aug"]]:["7","8"]}
Expected(options Jan, Jul selected, Aug selected)
Actual
Pass a JSON array as the selected parameter to pre-select more than one option, for a multiple select. Both Jul and Aug get the selected attribute.
test[{options:no_such_group_zz:1}]
Expected[]
Actual[]
A constants group id that does not exist returns nothing - no error, just empty output. The brackets confirm the empty string.
virtual{options:[[1,"January"],[2,"Feb"],[3,"March"]]:2}
Expected(options value=1 January, value=2 Feb selected, value=3 March)
Actual
A JSON array of value-label pairs. The first item of each pair is the option value, the second is the visible label. selected=2 marks the Feb option.