Best Practice for Debouncing Buttons/Preventing Double Clicks

Hi, was curious to see what the WeWeb recommended practice/what other folks have been doing for a couple of things:

  1. Preventing Double Clicks on Buttons

Having issue with buttons and users double clicking, which wreaks havoc on my analytics and database if I forget to add a safeguard.

Until now I’ve just been adding a disabled state, but this is less ideal for building fast and also results in a lot of variables cluttering up the interface.

Ideally would love to just have a fast way to debounce on each button I create, without having to add too much to the button.

Was thinking of adding this programmatically (unless there is a faster no code way!), but then that leads to the next question:

  1. What is the correct/recommended way to access “the current object” from its onClick or onMount handlers?

I’ve been playing around related queries, but those don’t seem the most reliable, eg sometimes the parent div returned from will be different.

Fetching the div by its id/class can work, but was wondering if there was an internal WeWeb way to access the current element that is kicking off the onClick?

Thanks in advance for any thoughts :slight_smile:

Hey, you could do a component, so you build this once, and use it everywhere, it also makes it easier to iterate. You could do a “loading / processing” state, it should be simple with states and component variables.

No need to do this with code :slight_smile: it should be or something along those lines, try console.log(event) in the Custom JavaScript action.

1 Like

@Broberto my dude many thanks! I had no idea there were component level variables - that makes life so much easier :slight_smile: I had a feeling I was missing some of kind of smarter “WeWeb” best practice way of doing things

On the JS side of things, I’ll give another try - I was playing around with grabbing the class of the parent of but it seemed like this wasn’t that reliable, it was missing a lot of fires

1 Like

Then you might want to have a look at the instance variable that WeWeb exposes

1 Like

Ahh thank you so much again!! Component variables have been working perfectly :star_struck:

I guess it’s no longer needed for this case, but will have to poke around and see if they do expose some kind of context from the onClick workflow. Unsure if this is not good practice to use this, but feels nice to have!

1 Like