Skip to content

form.addChoiceField

since 1.1.0

Add a choice field to the current form.

form.addChoiceField(line, rect, values, getValue, setValue)

Parameters

Name Type Required Description
line FormLine yes the line where the field should be added
rect Rect yes the coordinates
values table yes table of all possible values
getValue function yes the function which will return the current value
setValue function yes the function which will be called on value change

Returns

The new field

Examples

From the official Ethos documentation
form.addChoiceField(line, nil, values, function() return value end, function(newValue) value = newValue end)

Used in

Real-world usage

Called 188 times across 9 open-source Ethos Lua projects. A few short excerpts:
form.addChoiceField(axisLine, nil, AXES, function() return AXES[selected][2] end, onAxis)

src/rfsuite/app/pages/tune_advisor.lua:637

local field
if spec.choices then
  local access = configureChoiceSlot(runtime, spec)
  field = form.addChoiceField(line, slot, spec.choices, access.get, access.setWithDirty)

src/wfsuite/app/field_layout.lua:408

line = form.addLine("Certificate")
certField = form.addChoiceField(line, nil, certChoices,
    function() return widget.certIdx end,
    function(v) widget.certIdx = v; widget.mnvrIdx = 0 end)

src/bmfa-caller/widget_impl.lua:132