lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Scott Morgan wrote
> On 05/08/2017 03:35 AM, Pedro Alves wrote:
>> I'm here to announce AbsTK. The Abstract ToolKit is a widget toolkit for
>> GUI and TUI (text-based user interface) applications. It allows you to,
>> with the same source code, build a UI that runs on GUI (GTK) and TUI
>> (Curses).
>> *
>> <>
>> Any kind of feedback is strongly encouraged. I hope you enjoy it.
> I like the look of this, covers a lot of simple, everyday UI stuff neatly.
> Would it be possible to have some kind of validation for text fields?
> e.g. check if an email address is formatted correctly and alert the user
> if not. Make sure a checksum on a part number is correct.
> It'd seem the callback function would be it, but that doesn't return any
> data.
> Scott

Hi, Scott.

Surely would! You can do it:
1- When the submit request is sent (when the user clicks "Done")
2- From the callback, which is triggered to any change in field's content
3- Another widget to validade it

(1) Initially, I think of using the "Exit Callback" which is, basically, a
function that runs when the user finishes the form or wizard. On the wiki,
I've wrote an example that checks if the password field is empty and, if
it's not, it pops a dialog message demanding it to be filled.

(It is at the end of the page.)

(2) The second approach may be more invasive, because it may trigger while
the user is writting and that's much annoying. However, it's a good option
to, for instance, a field that only accepts numbers. You can erase the
non-numeric values just as they are written.

Example (please, do not do this):
local validate_email = function(id, value)
   if not value:match('^[%w.]+@%w+%.%w+$') then
      scr1:show_message_box("Invalid e-mail.")

scr1:add_text_input('email_field', "E-mail:", nil, "Enter your e-mail",

(3) And, finally, an individual widget just to this test. Like a "Validate
E-mail" button that has a callback to, obviously, validate the e-mail.

local validate_email = function(id, value)
   local email = scr1:get_value('email_field')
   if not email:match('^[%w.]+@%w+%.%w+$') then
      scr1:show_message_box("Invalid e-mail.")

scr1:add_text_input('email_field', "E-mail:", nil, "Enter your e-mail")
scr1:add_button('validate_email_button', "Validate e-mail", nil,

I think that's it. Tell me what you think.

Pedro Alves Valentim

View this message in context:
Sent from the Lua-l mailing list archive at