+ Start a Discussion
XactiumBenXactiumBen 

Clicking on a commandButton multiple times in a row results in action being fired multiple times

I have a strange issue that I never realised was an issue before:

 

I have a save button in one of my visualforce pages but when I click it multiple times in a row the action gets fired multiple times ending up in duplicates from the save process.  Should this be happening?

 

Is it best practice to disable all of my commandButtons when I click on it using javascript or have I just somehow broken some visualforce functionality that is already in place?

 

I'm a little confused (and slightly worried) - does it mean all of my commandButtons potentially have this problem?

bob_buzzardbob_buzzard

That's certainly the behaviour I've always seen.

 

I've handled this in a couple of ways in the past:

 

An ActionSupport on the commandbutton so that when it is clicked, some javascript disables some/all input elements on the page.  

 

Embedding the button inside a stop facet of an ActionStatus, so that it disappears when the user clicks it - though this obviously doesn't stop them clicking anything else.

  

jwetzlerjwetzler

Yeah, this is something you'll want to handle yourself.  Internally in our own setup pages (like the edit page for VF pages and components) we use javascript to disable the buttons once you click on them and restore them on oncomplete.

 

Please feel free to log an idea to the IdeaExchange.  If you have any ideas on how you'd want the design to look that would be helpful.

XactiumBenXactiumBen

I've disabled the buttons with javascript onclick of my commandButtons, then enabling again oncomplete.  It seems to work really well.

 

I think this is something I would want as standard within visualforce, but with the option to toggle the feature on and off using an attribute of some sort.

 

Link to idea: https://sites.secure.force.com/ideaexchange/ideaView?c=09a30000000D9xt&id=087300000007ZuS&returnUrl=%2Fapex%2FideaList%3Fc%3D09a30000000D9xt%26sort%3Drecent