Skip to main content

Checkbox

Properties

PropertyTypeOptionalDescription
textstringYesText displayed next to the checkbox
autoFocusbooleanYesWhen true, checkbox will be foxused when shown
checkedbooleanYesWeather the checkbox is checked
defaultCheckedbooleanYesWeather the checkbox is checked from the start
disabledbooleanYesWeather the checkbox is disabled
indeterminatebooleanYes"The indeterminate checked state of checkbox"
onChangefunction(event)YesFires when the user changes the checkbox
isGroupbooleanYesSee IsGroup
optionstableYesSee IsGroup
defaultValuestringnumber[]Yes

See more properties here.

Children

Checkbox does not support children.

Example

local checkbox = myUI:createElement("Checkbox", {
text = "Awesome",
defaultChecked = true,
onChange = function(id, name, event)
local target = event.target
local checked = target.checked
print("Checkbox Changed: Checked: " .. tostring(checked))
end,
})

How it looks:

How it Looks

When the checkbox is clicked the onChange will print Checkbox Changed: Checked: true/false

Text

The text displayed besides the checkbox.

From the example the text is "Awesome"

AutoFocus

When true the checkbox is focused when shown to the user.

Checked

Weather the checkbox is checked.

Note when set, you will have to overwrite the onChange functionality otherwise the checkbox will stay checked or unchecked.

onChange = function(id, name, event)
local target = event.target
local checked = target.checked
checkbox.checked = checked
end

onChange runs with what the value should actually be.

DefaultChecked

Weather the checkbox is checked by default.

Disabled

Weather the checkbox is disabled.

Disabled Checkbox

Indeterminate

"The indeterminate checked state of checkbox"

???

OnChange

Event is fired when the user checks/unchecks the checkbox.

Note when IsGroup is true the functionality changes!

Heres what it looks like normally:

Print Example

IsGroup

When true options is required!

Example

local plainOptions = {"Apple", "Pear", "Orange"}
local options = {
{ label = 'Apple', value = '_apple' },
{ label = 'Pear', value = '_pear' },
{ label = 'Orange', value = '_orange' },
}
local optionsWithDisabled = {
{ label= 'Apple', value= '_apple' },
{ label= 'Pear', value= '_pear', disabled = true },
{ label= 'Orange', value= '_orange', disabled = false },
}

local checkbox1 = myUI:createElement("Checkbox", {
isGroup = true,
options = plainOptions,
onChange = function(id, name, checkedValues)
print("Checked Values: ", json.encode(checkedValues))
end,
})
local checkbox2 = myUI:createElement("Checkbox", {
isGroup = true,
options = options,
onChange = function(id, name, checkedValues)
print("Checked Values: ", json.encode(checkedValues))
end,
})
local checkbox3 = myUI:createElement("Checkbox", {
isGroup = true,
options = optionsWithDisabled,
defaultValue = {"Apple", "Orange"},
onChange = function(id, name, checkedValues)
print("Checked Values: ", json.encode(checkedValues))
end,
})

Showcase

Options Properties
PropertyTypeOptionalDescription
labelstringYesLabel of the entry/option
valuestringYesValue of the entry, what comes with onChange
disabledbooleanYesWeather the entry is disabled