Boolean input
A boolean input field rendered as a checkbox or switch.
ctx.ui.inputs.boolean("name", config);
Config
name*
string
The name of the input. This will be the key in the result object.
label
string
The label of the input. If this is not provided, the name will be used as the label.
helpText
string
The help text of the input.
optional
boolean
Whether the input is optional. Inputs are required by default.
disabled
boolean
Whether the input is disabled.
defaultValue
boolean
The default value of the input.
mode
"checkbox" | "switch"
Defines how the boolean input is rendered. "checkbox"
renders a standard checkbox, "switch"
renders
a toggle switch. Default is "checkbox"
.
Usage
Elements are rendered by adding them to a page
. A page that contains input elements will return an object with keys matching the name
of each input.
const result = await ctx.ui.page({
title: "Boolean inputs",
content: [
ctx.ui.inputs.boolean("acceptTerms"),
ctx.ui.inputs.boolean("enableFeatures", {
label: "Enable advanced features",
defaultValue: true,
mode: "switch",
}),
],
});
console.log(result.acceptTerms);
console.log(result.enableFeature);