How To Call It
Form is a global table: call its functions with a dot (Form.<method>(...)), not a colon. Requires Macro Handler 1.0.51 or later.
Checks a form schema without opening a window; returns true, or false and an explanation.
Documented for app version 1.0.50Updated:
Form is a global table: call its functions with a dot (Form.<method>(...)), not a colon. Requires Macro Handler 1.0.51 or later.
Checks a form schema without opening a window; returns true, or false and an explanation.
The schema contains a fields array and optional title, positive, negative, surface and timeoutMs. Field types include input, checkbox, radio, select, multi, tags, signature, image, color, file, datetime, range, slider, recorder, navigation and agentDetect; layouts include text/spacer, row/section and tabs. Keys must be unique; radio/select/tabs selected indices start at 1. Up to 256 fields and 8 layout levels are accepted.
Use visibleWhen = {{key="enabled", value=true}} for conditional visibility and required, pattern, help and style for field rules. Cyclic visibility and invalid schemas are rejected. Form uses the shared Setting renderer; it does not execute custom HTML or external code. Checkbox defaults are boolean; other values are strings. Radio/select and tabs return the selected label; multi returns comma-separated labels. Use tonumber before numeric operations.
The snippet below is a starter pattern that can be applied directly in runtime flow.
local schema = {title = "Run settings", positive = "Start", negative = "Cancel", fields = {
{type = "checkbox", key = "enabled", label = "Enabled", value = true},
{type = "input", key = "target", label = "Target", value = "Example", required = true},
{type = "slider", key = "count", label = "Count", min = 1, max = 10, value = 3},
{type = "select", key = "mode", options = {"Safe", "Fast"}, selected = 2},
{type = "multi", key = "steps", label = "Steps", options = {"Scan", "Report"}, value = {"Scan"}}
}}
local ok, message = Form.validate(schema)
print(ok, message)From foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.
local schema = {title = "Run settings", positive = "Start", negative = "Cancel", fields = {
{type = "checkbox", key = "enabled", label = "Enabled", value = true},
{type = "input", key = "target", label = "Target", value = "Example", required = true},
{type = "slider", key = "count", label = "Count", min = 1, max = 10, value = 3},
{type = "select", key = "mode", options = {"Safe", "Fast"}, selected = 2},
{type = "multi", key = "steps", label = "Steps", options = {"Scan", "Report"}, value = {"Scan"}}
}}
local ok, message = Form.validate(schema)
print(ok, message)local stepOk = true
local schema = {title = "Run settings", positive = "Start", negative = "Cancel", fields = {
{type = "checkbox", key = "enabled", label = "Enabled", value = true},
{type = "input", key = "target", label = "Target", value = "Example", required = true},
{type = "slider", key = "count", label = "Count", min = 1, max = 10, value = 3},
{type = "select", key = "mode", options = {"Safe", "Fast"}, selected = 2},
{type = "multi", key = "steps", label = "Steps", options = {"Scan", "Report"}, value = {"Scan"}}
}}
local ok, message = Form.validate(schema)
print(ok, message)
if stepOk then
wait(200)
endlocal ok, err = pcall(function()
local schema = {title = "Run settings", positive = "Start", negative = "Cancel", fields = {
{type = "checkbox", key = "enabled", label = "Enabled", value = true},
{type = "input", key = "target", label = "Target", value = "Example", required = true},
{type = "slider", key = "count", label = "Count", min = 1, max = 10, value = 3},
{type = "select", key = "mode", options = {"Safe", "Fast"}, selected = 2},
{type = "multi", key = "steps", label = "Steps", options = {"Scan", "Report"}, value = {"Scan"}}
}}
local ok, message = Form.validate(schema)
print(ok, message)
end)
if not ok then
print("API step failed: Form.validate: " .. tostring(err))
requestStop()
end-- Form.validate(schema)
local function run_validate_step()
local schema = {title = "Run settings", positive = "Start", negative = "Cancel", fields = {
{type = "checkbox", key = "enabled", label = "Enabled", value = true},
{type = "input", key = "target", label = "Target", value = "Example", required = true},
{type = "slider", key = "count", label = "Count", min = 1, max = 10, value = 3},
{type = "select", key = "mode", options = {"Safe", "Fast"}, selected = 2},
{type = "multi", key = "steps", label = "Steps", options = {"Scan", "Report"}, value = {"Scan"}}
}}
local ok, message = Form.validate(schema)
print(ok, message)
end
local ok, err = pcall(run_validate_step)
if not ok then
toast("Step failed")
print(err)
endlocal schema = {title = "Run settings", positive = "Start", negative = "Cancel", fields = {
{type = "checkbox", key = "enabled", label = "Enabled", value = true},
{type = "input", key = "target", label = "Target", value = "Example", required = true},
{type = "slider", key = "count", label = "Count", min = 1, max = 10, value = 3},
{type = "select", key = "mode", options = {"Safe", "Fast"}, selected = 2},
{type = "multi", key = "steps", label = "Steps", options = {"Scan", "Report"}, value = {"Scan"}}
}}
local ok, message = Form.validate(schema)
print(ok, message)