Unable to add text from a textbox to a label on click of a button in gowut

21 views
Skip to first unread message

ati...@mail.ccsf.edu

unread,
Jun 2, 2018, 1:39:30 PM6/2/18
to gowebuitoolkit
Hello,

I have decided to use gowut as my main GUI solution.

I have been messing around with it and have been unable to complete a simple task.
I am trying to add text from a textbox to a label on the click of a button.

It only updates when I refresh the page with the text in the textbox not when I click the button?

Hopefully someone can look at this code and tell me what I am doing wrong, Thanks!

András Belicza

unread,
Jun 2, 2018, 3:09:05 PM6/2/18
to ati...@mail.ccsf.edu, gowebuitoolkit
Hi there,

This is how you register the event handler:

greetButton.AddEHandlerFunc(func(e gwu.Event) {
if e.Type() == gwu.ETypeClick {
outputLabel.SetText(nameTextBox.Text())
}
}, gwu.ETypeClick)

When you change some components in a handler, you have to tell gowut about them so gowut can take care of automatically rendering them again.

For this, use the Event.MarkDirty() method like this:

greetButton.AddEHandlerFunc(func(e gwu.Event) {
if e.Type() == gwu.ETypeClick {
outputLabel.SetText(nameTextBox.Text())
e.MarkDirty(outputLabel)
}
}, gwu.ETypeClick)


This will make it work.

Also note that if you register a handler with a single event type, you do not need to check it (it's redundant). So this handler does exactly what yours:

greetButton.AddEHandlerFunc(func(e gwu.Event) {
outputLabel.SetText(nameTextBox.Text())
e.MarkDirty(outputLabel)
}, gwu.ETypeClick)

Regards,
Andras


ati...@mail.ccsf.edu

unread,
Jun 2, 2018, 7:05:18 PM6/2/18
to gowebuitoolkit
Thanks so much, this fixed my issue. I had seen something about marking something dirty but tried and marked the button dirty.....didn't really understand what it did. Also, thanks for the tip about not having to check if it is the right event as well.

Augy
Reply all
Reply to author
Forward
0 new messages