Beginner questions on gowut

124 views
Skip to first unread message

Everton Marques

unread,
Jun 16, 2016, 10:31:01 AM6/16/16
to gowebuitoolkit
Hi,

I have two very basic questions about using gowut.

1. I am looking at the login example.
One is supposed to mouse-left-click the OK button to proceed.
How can I trap the RETURN key to trigger the same effect as the OK button? 

2. What is the recommended way to store data under sessions?
For instance, I would like to save the login username into a session.

Can anyone please share pointers on these issues?

Thanks,
Everton

András Belicza

unread,
Jun 16, 2016, 11:11:05 AM6/16/16
to gowebuitoolkit
1. You could add event handlers to the user name and password text boxes, bounded to the event type ETypeKeyPress.
In that handler, check if the pressed key is the Enter, and if so, execute the same thing that currently is when the OK button is clicked.
To check if pressed key is enter in an event handler:

    if e.Type() == gwu.ETypeKeyPress && e.KeyCode() == gwu.KeyEnter {
        // enter key was pressed
    }

2. Check the doc of the Session type: https://godoc.org/github.com/icza/gowut/gwu#Session
Session has a SetAttr() method to set an attribute, and an Attr() method to get the value of a previously set attribute. For example in an event handler:

    sess := e.Session()
    if sess.Private() {
        // To store the username in the session:
        sess.SetAttr("username", "Bob")

        // To access username:
        uname := sess.Attr("username").(string)
    }

Regards,
Andras

Everton Marques

unread,
Sep 16, 2016, 5:39:55 PM9/16/16
to gowebuitoolkit
Hi,

I have tried your suggestion of attaching event handlers to text box and password box.
It works.

However, I see this glitch:
1. Enter username.
2. Enter password.
3. Hit enter immediately after the password.
4. The event handler gets an empty string as text from the password box, so the auth fails.
5. If I hit enter again, the event handler is able to read the correct text from the password box.

What am I missing?

Thanks,
Everton

András Belicza

unread,
Sep 16, 2016, 5:49:30 PM9/16/16
to gowebuitoolkit
My guess is that the HTTP request which synchronizes the values of the text and password boxes have not completed before the handler for the Enter is processed. Do you experience the same when running it locally?

Everton Marques

unread,
Sep 16, 2016, 6:10:15 PM9/16/16
to gowebuitoolkit
Yes, I have tested locally only.

1. I have just tested it again: waited 10 seconds before hitting enter, and the password box returned an empty string as text.
2. The obvious work-around is to hit enter again. I think this works because the invalid login code focuses the username box (taking it out of the password box).
3. I can work-around the issue by mouse left clicking the username text box before hitting enter.
4. The issue does not affect mouse left clicks. I guess this is because the left click event takes the focus out of the password box onto the OK button.

Everton Marques

unread,
Sep 19, 2016, 11:29:06 AM9/19/16
to gowebuitoolkit
For the records, the issue has been fixed by attaching .AddSyncOnETypes(gwu.ETypeKeyUp):

tb := gwu.NewTextBox("")
tb.AddSyncOnETypes(gwu.ETypeKeyUp) // synchronize values during editing (while you type in characters)

pb := gwu.NewPasswBox("")
pb.AddSyncOnETypes(gwu.ETypeKeyUp) // synchronize values during editing (while you type in characters)

This fix was based on the following comment:

// If you want a TextBox to synchronize values during editing
// (while you type in characters), add the ETypeKeyUp event type
// to the events on which synchronization happens by calling:
//              AddSyncOnETypes(ETypeKeyUp)


Everton

András Belicza

unread,
Sep 19, 2016, 3:15:13 PM9/19/16
to Everton Marques, gowebuitoolkit
Cool :) Thanks for sharing it.
Reply all
Reply to author
Forward
0 new messages