Activity Forums Salesforce® Discussions Disable commandButton after first click to prevent double submission

  • Surbhi

    Member
    June 1, 2016 at 6:29 am

    Hi Himanshu,

    I suggest to use a JavaScript function called by button's onclick event, which internally calls an actionFunction to post the form, disables the buttons on the page and then returns false on the button. And oncomplete event will re-enable the button when the form has been (ajax) posted and returns a result to the page.

    Thanks

  • Gourav

    Member
    July 5, 2016 at 2:23 pm

    Hi Himanshu,

    You can try this approach

    <apex:pageBlockButtons>
    <apex:actionStatus id="status" >
    <apex:facet name="start">
    <apex:outputPanel >
    Merging... <apex:image value="{!URLFOR($Resource.blueSquares)}"/>
    </apex:outputPanel>
    </apex:facet>
    <apex:facet name="stop">
    <apex:outputPanel >
    <apex:commandButton value="Merge" action="{!mergeOpps}" rerender="error1,error2" status="status"/>
    <apex:commandButton value="Cancel" action="{!cancel}" immediate="true"/>
    </apex:outputPanel>
    </apex:facet>
    </apex:actionStatus>
    </apex:pageBlockButtons>

     

    In this we use apex:actionStatus for this.

    Hope this will help.

  • Sourabh

    Member
    July 15, 2016 at 1:47 pm

    You can use javascript for disabling button after the click. Here is a piece of code for that.

    <apex:commandButton value="Submit" id="Submit" onClick="SubmitOnClick(this);" />

    <apex:actionFunction name="doSubmit" action="{!Submit}" />
    </apex:form>

    <script language="Javascript">
    function SubmitOnClick (objSubmitBtn) {
    objSubmitBtn.disabled = true;
    objSubmitBtn.value = 'Submitting...';
    doSubmit();
    }
    </script>

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos