+ Start a Discussion
S SaiS Sai 

how to disable apex:commandlink after first click in visualfroce page ?

Hi 

how to disable commnadlink after first click 

Thanks
Sai
Amit Chaudhary 8Amit Chaudhary 8
I guess this is not out of the box and Idea is already raised for same
1) https://success.salesforce.com/ideaView?id=08730000000kyhqAAA

Please try <apex:outputlink> , it has disable attribute and works also same as commandLink

Try below code. I hope that will help you :-
http://salesforce.stackexchange.com/questions/7729/disable-commandbutton-after-first-click-to-prevent-double-submission
<script src="//ajax.googleapis.com/ajax/libs/jquery/latest/jquery.js"></script>
<script>

    function buttonsEnabled(enabled) {
        // retrieve all of the buttons or links on the page
        // with the css class of btn
        var $buttons = jQuery('.btn');
        if (enabled === false) {
            // add the btnDisabled class to give it the look of being disabled
            // add the disabled attribute to actually disable interactability
            $buttons.toggleClass('btnDisabled', true).attr('disabled', 'disabled');
        } else {
            // remove the css class and the disabled attribute
            $buttons.toggleClass('btnDisabled', false).attr('disabled', null);
        } 
    }

    function doSomeWork() {
        // first, call the action function to post the form
        doSomeWorkActionFunction();

        // second, disable the buttons
        buttonsEnabled(false);

        // third, return false to prevent the click from
        // posting the form a second time
        return false;
    }

</script>

<apex:form>

    <apex:actionFunction name="doSomeWorkActionFunction" 
        action="{!yourControllerMethod}" 
        oncomplete="buttonsEnabled(true);"
        rerender="whateverYouNeedToRerender"></apex:actionFunction>

    <apex:commandLink action="{!yourControllerMethod}" 
        value="Your Text Here" 
        id="theCommandLink" 
        onclick="return doSomeWork();" />

</apex:form>

Let us know if this will help you

 
S SaiS Sai
Hi Amit,
I want to disable after clicking 
Thanks 
sai
JeffreyStevensJeffreyStevens
In the constructor of the controller, set a boolean (like disableButton = false;) In the action method that the commandButton calls - set it to true.  In the page - use the disabled="{!disableButton}" attribute of the CommandButton element.