form.addTextField¶
since 1.1.0
Add a text field to the current form.
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 text |
setValue |
function | yes | the function which will be called on text change |
Returns¶
The new field
Examples¶
From the official Ethos documentation
form.addTextField(line, nil, function() return text end, function(newValue) text = newValue end)
form.addTextField(line, {x=200, y=0, w=100, h=40}, function() return text end, function(newValue) text = newValue end)
form.addTextField(line, form.getFieldSlots(line, {100, 0, "slot3"})[0], function() return text end, function(newValue) text = newValue end)
Used in¶
Real-world usage¶
Called 4 times across 4 open-source Ethos Lua projects. A few short excerpts:
control = form.addTextField(form.addLine("@i18n(app.modules.configuration.craft_name)@"), textFieldPos(app),
function()
return state.currentName
end,
function(newValue)
local value = tostring(newValue or "")
if value ~= state.currentName then
state.currentName = value
state.dirty = true
app:setPageDirty(true)
end
end)
-- header comment for why: the first page needing one, and why it
-- can't be corrected in place like every other field type).
local nameLine = form.addLine("@i18n(app.modules.configuration.craft_name)@")
local nameField = form.addTextField(nameLine, nil,
function()
local craftName = dataRef.data.craftName
return craftName and craftName.name or ""
end,
function(value)
markDirty()
local craftName = dataRef.data.craftName
if craftName then craftName.name = value or "" end
end)
formFields[i] = form.addTextField(formLines[dashx.session.formLineCnt], posField, function()
if not fields or not fields[i] then
ui.disableAllFields()
ui.disableAllNavigationFields()
ui.enableNavigationField('menu')
return nil
end
return dashx.app.utils.getFieldValue(fields[i])
end, function(value)
if f.postEdit then f.postEdit(page) end
if f.onChange then f.onChange(page) end
f.value = dashx.app.utils.saveFieldValue(fields[i], value)
end)