2

I have used page block button in one page for save button so that I can have two save buttons at the top and buttom of the page.I have to disable the both the save button once clicked both at top and buttom of page.But, while clicking the button at the buttom, button present at the top of the page is not disabled and it allows the user to click it.I have already tried thejava script for this functionality also.But in both the cases only one button getting disabled.Appreciate any help!

<apex:pageBlockButtons >
      <apex:actionStatus id="saveStatus"> 
        <apex:facet name="stop">
            <apex:commandButton title="Save" value="Save" style="padding:2px 6px;" action="{!saveRecord}" accesskey="Enter" reRender="pgBlockMsgs" status="saveStatus" onclick="scroll()">
              <apex:param value="{!stringSave}" name="saveType" assignTo="{!saveType}" />
            </apex:commandButton>               
        </apex:facet>
        <apex:facet name="start">
          <apex:outputPanel >
             <apex:image value="/img/loading32.gif" style="height: 20px;"/>
             <apex:commandButton value="Processing..." status="saveStatus" disabled="true"/>
          </apex:outputPanel>
        </apex:facet>     
     </apex:actionStatus>
1

Use a simple Javascript function for disabling buttons. Assign some extra css class to the pageBlock button and disable/enable only these buttons. If one of these buttons is clicked - disable the both. When the action is complete - enable both buttons again:

<script>
function blockReleaseBtns(disable){
    var btns = document.getElementsByClassName('saveBtnClass');
    for(var i = 0; i < btns.length; i++){
        if(disable){
            btns[i].disabled = 'disabled';
            btns[i].className = 'saveBtnClass btnDisabled'; 
        }
        else {
            btns[i].disabled = '';
            btns[i].className = 'saveBtnClass btn'; 
        }
    }
}
</script>

<apex:pageBlock>
    <apex:pageBlockButtons>

        <apex:commandButton value="Save" reRender="pgBlockMsgs" status="saveStatus"
                            styleClass="saveBtnClass"
                            onclick="blockReleaseBtns(true);"
                            oncomplete="blockReleaseBtns(false);"/>     

        <apex:actionStatus id="saveStatus">
            <apex:facet name="start">
                 <apex:image value="/img/loading.gif" style="height:20px;"/>
            </apex:facet> 
        </apex:actionStatus> 

     </apex:pageBlockButtons>
</apex:pageBlock>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.