Skip to content

form.addNumberField

since 1.1.0

Add a number field to the current form.

form.addNumberField(line, rect, min, max, getValue, setValue)

Parameters

Name Type Required Description
line FormLine yes the line where the field should be added
rect Rect yes the coordinates
min integer yes the min value
max integer yes the max value
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
local myField = form.addNumberField(line, nil, minValue, maxValue, function() return value end, function(newValue) value = newValue end)
myField:suffix("mAh")
myField:default(0)
myField:step(2)

Used in

Real-world usage

Called 229 times across 6 open-source Ethos Lua projects. A few short excerpts:
line = panel:addLine("Max RPM")
rpmMaxEdit = form.addNumberField(line, nil, 0, 10000, function() return widget.maxRpm end, function(newValue) widget.maxRpm = newValue end)

lua/frsky/JetWidget/main.lua:306

local rpm_max_line = rpm_panel:addLine("Max")
formFields[#formFields + 1] = form.addNumberField(rpm_max_line, nil, 1, 20000, function() return config.rpm_max end, function(val) config.rpm_max = clamp(tonumber(val) or THEME_DEFAULTS.rpm_max, config.rpm_min + 1, 20000) end, 1)

src/rfsuite/widgets/dashboard/themes/kevd/configure.lua:53

local esc_max_line = esc_panel:addLine("Max")
formFields[#formFields + 1] = form.addNumberField(esc_max_line, nil, 1, 200, function() return config.esctemp_max end, function(val) config.esctemp_max = clamp(tonumber(val) or THEME_DEFAULTS.esctemp_max, config.esctemp_warn + 1, 200) end, 1)

src/wfsuite/widgets/dashboard/themes/kevd/configure.lua:98