Skip to content

form.addBooleanField

since 1.1.0

Add a boolean field to the current form.

form.addBooleanField(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 line = form.addLine("Voice alerts")
form.addBooleanField(line, nil,
  function() return config.voice end,
  function(v) config.voice = v end)
From the official Ethos documentation
form.addBooleanField(line, nil, function() return value end, function(newValue) value = newValue end)

Used in

Real-world usage

Called 54 times across 5 open-source Ethos Lua projects. A few short excerpts:
formFieldCount = formFieldCount + 1
dashx.session.formLineCnt = dashx.session.formLineCnt + 1
dashx.app.formLines[dashx.session.formLineCnt] = form.addLine("@i18n(app.modules.settings.txt_devtools)@")
dashx.app.formFields[formFieldCount] = form.addBooleanField(dashx.app.formLines[dashx.session.formLineCnt], nil, function() if dashx.preferences and dashx.preferences.developer then return settings['devtools'] end end,
                                           function(newValue) if dashx.preferences and dashx.preferences.developer then settings.devtools = newValue end end)

src/dashx/app/modules/settings/tools/development.lua:26

form.addBooleanField(form.addLine("@i18n(app.modules.settings.shortcuts_mixed_in_mode)@"), nil,
    function()
        return self.state.mixedIn == true
    end,
    function(newValue)
        self.state.mixedIn = prefBool(newValue, true)
    end)

src/rfsuite/app/modules/settings/tools/shortcuts.lua:117

line = form.addLine("@i18n(app.modules.blackbox.rolling_erase)@")
controlFields.rollingErase = form.addBooleanField(line, nil, function()
  return (current.rollingErase or 0) == 1
end, function(value)
  current.rollingErase = value and 1 or 0
  markDirty()
end)

src/rfsuite/app/pages/blackbox_edit_page.lua:364