Skip to main content

! Present dialog and return user selection (:show)

Declaration

confirmed, selections = dlg:show()

Returns

  • confirmed
    Boolean. Whether the Submit button was pressed. Returns false on timeout or when closed by the “×”.
  • selections
    Table. A key-value table mapped by option labels.

Notes

Present the dialog and return the user's selections.
If configuration saving is enabled via :set_config(name), pressing Submit saves the config; closing with “×” or timing out does not.

Simple example

local c, s = dialog():add_switch('A switch', false):show()
sys.alert(s['A switch'])

Note: Uses sys.alert

Complex example

local dlg = dialog() -- create dialog object
--
-- configure dialog
dlg:set_config('test') -- config storage ID
dlg:set_timeout(30)
dlg:add_label('Simple demo')
dlg:add_range('HP', {0, 1000, 1}, 300)
dlg:add_input('Account', 'ccc')
dlg:add_input('Password', 'aaaa')
dlg:add_picker('Gender', {'Male', 'Female', 'Unknown'}, 'Male')
dlg:add_switch('Are you abnormal?', false)
dlg:add_checkbox('Favorite games', {'Overwatch', 'World of Warcraft', 'Hearthstone'}, {'Overwatch', 'World of Warcraft'})
dlg:add_radio('Most favorite game', {'Overwatch', 'World of Warcraft', 'Hearthstone'}, 'World of Warcraft')
--
local confirm, selects = dlg:show() -- present and get result
--
if (confirm) then
print("You pressed Submit")
else
print("You did not press Submit")
end
--
print("Account", selects["Account"])
print("Password", selects["Password"])
print("Gender", selects["Gender"])
print("HP", selects["HP"])
--
if (selects['Are you abnormal?']) then
print("You admitted you are abnormal")
else
print("You did not admit you are abnormal")
end
--
print("Your favorite games")
for _, gamename in ipairs(selects['Favorite games']) do
print(gamename)
end
--
print("Your most favorite game:"..selects["Most favorite game"])
--
sys.alert(print.out())

Note: Uses sys.alert, print, print.out