Skip to content
Pedro Alves Valentim edited this page Mar 28, 2017 · 7 revisions

AbsTK UI data is stored, sorted and returned, as table, at the end of run() function, on both Screen and Wizard. Data tables store widgets data as key/value pairs, where key is the widget ìd and value vary depending on the widget type. For instance, the value of a text input is the string inside the field.

Screen

To this example:

local abstk = require 'abstk'
abstk.set_mode(...)

local scr = abstk.new_screen("Register Form")

scr:add_label('label', "Fill the fields to register")
scr:add_text_input('email', "E-mail")
scr:add_text_input('user', "Username")
scr:add_password('pswrd', "Password")
scr:add_checkbox('news', "Send me newsletter")

local data = scr:run()

Considering user input being:

E-mail: [email protected]
Username: admin
Password: admin123
Send me newsletter: *check*

data is like:

{
	label = "Fill the fields to register",
	email = "[email protected]",
	user = "admin",
	pswrd = "admin123",
	news = true,
}

Wizard

To this example:

local abstk = require 'abstk'
abstk.set_mode(...)

local wizard = abstk.new_wizard("Registration Wizard", 800, 600)

local scr1 = abstk.new_screen("Register")
local scr2 = abstk.new_screen("Thanks")

scr1:add_label('label', "Fill the fields to register")
scr1:add_text_input('email', "E-mail")
scr1:add_text_input('user', "Username")
scr1:add_password('pswrd', "Password")

scr2:add_label('thanks', "Thank you for your registration.")
scr2:add_checkbox('news', "Send me newsletter")

wizard:add_page('register_page', scr1)
wizard:add_page('thanks_page', scr2)

local data = wizard:run()

Considering user input being:

(On the first page)
E-mail: [email protected]
Username: admin
Password: admin123

(On the second page)
Send me newsletter: *check*

data is like:

{
	register_page = {
		label = "Fill the fields to register",
		email = "[email protected]",
		user = "admin",
		pswrd = "admin123",
   },
   thanks_page = {
		thanks = "Thank you for your registration.",
		news = true,
	}
}

IMPORTANT: As you can see, Wizard doesn't get only the widgets data but, also, arrange them to their pages data sub-table. This is not just a matter of organization but, also, because of the fact that widgets, on Wizards, can be homonymous. Since widgets are added directly to Screens, and manipulated inside them (as in scr:set_value(...)), this is not a problem.

Clone this wiki locally