Skip to content

form.addSourceField

since 1.1.0

Add a source field to the current form.

form.addSourceField(line, rect, getValue, setValue)

Parameters

Name Type Required Description
line FormLine yes the line where the field should be added
rect Rect yes the coordinates
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

local function configure(widget)
  local line = form.addLine("Source")
  form.addSourceField(line, nil,
    function() return widget.source end,
    function(value) widget.source = value end)
end

local function write(widget) storage.write("source", widget.source) end
local function read(widget) widget.source = storage.read("source") end
From the official Ethos documentation
form.addSourceField(line, nil, function() return source end, function(newValue) source = newValue end)

Used in

Real-world usage

Called 6 times across 1 open-source Ethos Lua project. A few short excerpts:
line = form.addLine("Pump source")
form.addSourceField(line, nil, function() return widget.pumpSource end, function(newValue) widget.pumpSource = newValue end)

lua/frsky/JetWidget/main.lua:357

local line = form.addLine("Altitude source")
form.addSourceField(line, nil, function() return widget.altSource end, function(newValue) widget.altSource = newValue end)

lua/frsky/JetWidget/main.lua:294

panel = form.addExpansionPanel("EGT configure")
local egtMaxEdit
line = panel:addLine("EGT source")
form.addSourceField(line, nil, function() return widget.egtSource end, function(newValue)
  widget.egtSource = newValue
  if egtMaxEdit ~= nil then
    egtMaxEdit:suffix(widget.egtSource ~= nil and widget.egtSource:stringUnit() or "")
  end
end)

lua/frsky/JetWidget/main.lua:342