Monday 3 March 2014

Restricting User to Double Click on Button

Hey Guys !!!

This post is regarding to avoid one small issue I have come across it.
Let say there is a visual force page where input fields and one button is present. When that button is clicked records are inserted in to the object. If button is clicked twice in same time(double click) then records(duplicate records ) are being created twice. 

How will we avoid that?
How will restrict user to do double click on button?

Here I am sharing some snippet of code.Hope It will help you.

Visualforce Page


<apex:page standardController="Account">
    <apex:form >
        <apex:pageMessages id="messages"></apex:pageMessages>
        <apex:pageBlock title="Avoid Doublle Click" >
            <apex:pageBlockButtons location="both">
                
                <apex:actionStatus id="saveStatus">
                    
                    <apex:facet name="stop">
                        <apex:outputPanel >
                            <apex:commandButton action="{!save}" value="{!$Label.ButtonSavePage}" reRender="messages" status="saveStatus"/>
                            <apex:commandButton action="{!Cancel}" value="Cancel" immediate="true" />
                        </apex:outputPanel>
                    </apex:facet>
                    <apex:facet name="start">
                        <apex:outputPanel >
                            <apex:commandButton value="Saving..." disabled="true" />
                            <apex:commandButton value="Saving..." disabled="true" />
                       </apex:outputPanel>
                         
                    </apex:facet>
                                 
                </apex:actionStatus>
                  
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Account Creating">
                <apex:inputField value="{!Account.Name}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
  
</apex:page>

1 comment:

Unknown said...

Nice post Asish..!!! I tried this in my dev Org. it is only disabling the upper buttons in page block table, if i want the same for below buttons also as like salesforce standard , what should i do for it . i think you will come up with proper solution. Good job ....:)