WebPushButton : debounce (prevent multiple clicks)

In my Web 2 solution I have a page with a button which shows a dialog box. In normal operation it works like this:

WebPage1.WebButton.Pressed
WebPage1.WebMessageDialog1.Show
WebPage1.WebMessageDialog1.ButtonPressed
WebPage1.WebMessageDialog1.Closed

However, occasionally I see this happen:

WebPage1.WebButton.Pressed
WebPage1.WebButton.Pressed
WebPage1.WebButton.Pressed
WebPage1.WebButton.Pressed
WebPage1.WebButton.Pressed
WebPage1.WebButton.Pressed
WebPage1.WebMessageDialog1.Show
WebPage1.WebMessageDialog1.ButtonPressed
WebPage1.WebMessageDialog1.Closed

I have not seen this from the user’s side, so I’m not sure if:

  • the user is getting frustrated and clicking the button multiple times because the UI is slow to respond
  • there is a bug in Xojo Web which is somehow causing multiple .Pressed events to fire

Either way, I feel like this should not be happening.

I can reproduce this if I simulate a poor network, using Network Link Conditioner:

Then I’m able to click a button repeatedly in the UI. In this case I was able to get 3 clicks in before the Dialog box showed up:

WebPage1.WebButton.Pressed
WebPage1.WebButton.Pressed
WebPage1.WebButton.Pressed
WebPage1.WebMessageDialog1.Show

While I could work around this by doing something like this:

WebPage1.WebButton.Pressed
  if bIAmProcessingEvent = true then
       system.debugLog CurrentMethodName + " multiple events, ignored"
       return
  end if
  bIAmProcessingEvent = true
  [ ... do stuff ... ]
  bIAmProcessingEvent = false

this would require me to add a tremendous amount of extra code and logic to my WebApp.

I think this is something that the framework should handle for us.

As it currently works, this is a big difference in function between Desktop and Web:

  • On Desktop, you generally can’t trigger one event while another one is being processed. - And, if you do, the second event will only happen after the first event’s handler has completed, not before.

Have you tried WebButton.AllowAutoDisable = true?

Yeah, the web is asynchronous and you have to build your app around that. My best results come from adding even more back and forth to the communication, it’s not an optimal solution.

4 Likes

Wow, I had no idea that AllowAutoDisable exists!

I just tried it, and it does seem to prevent multiple clicks on the WebButton from firing the Pressed event more than once.

I suspect there are more controls where this is an issue, but for now I think this lets me solve my most immediate issue…