function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dharmendra PahadiyaDharmendra Pahadiya 

Disable vf page save button....

Hi,

I want to disable a vf page save button which is in <apex:pageBlockButtons> block. I have read many articles related to this and tried them but none had helped me.

I have tried the action function from some other post but its posting my data twice to server.
Please see below my code.

<apex:actionStatus id="mySaveStatus1"> <apex:facet name="stop"> <apex:commandButton action="{!saveOverride}" status="mySaveStatus1" value="Save" disabled="false" rerender="pgMsg"/> </apex:facet> <apex:facet name="start"> <apex:commandButton status="mySaveStatus1" value="Saving..." disabled="true"/> </apex:facet>

Please suggest me a way to get this done.
Thanks in advance.
Roy LuoRoy Luo
You may want to consider show/hide the Save button by binding 'rendered' to a Boolean defined in your controller.
 
<apex:commandButton action="{!saveOverride}" status="mySaveStatus1" value="Save" rendered="{!showSaveButton}" rerender="pgMsg"/>
 
public Boolean showSaveButton {get; set;}

 
praveen kumar thotapraveen kumar thota
Hi Dharmendra,

You can go disable a button through a Boolean value
 
<apex:facet name="stop">
  <apex:commandButton action="{!saveOverride}" status="mySaveStatus1" value="Save" disabled="{!disablebtn}" rerender="pgMsg"/> 
 </apex:facet> 
 <apex:facet name="start"> 
  <apex:commandButton status="mySaveStatus1" value="Saving..." disabled="{!disbalestatus}"/> 
 </apex:facet>


Controller

public boolean disablebtn{get; set;}
public boolean disablestatus{get; set;}

Button will be still visible after disabling but i wont work.i hope this will help you.
Dharmendra PahadiyaDharmendra Pahadiya
Thanks for your reply....
But I have tried both solutions but they are nor working for me.
The problem with my code is just that it is calling the saveOverride method twice.
If i try to save the record considering all the validations then it is working fine. 
But if I try to save the record and any custom validation error occurs then the saveOverride method exit but it automatically started again which is causing problem....
Please try to give me answer in this scenerio. What is happening??
praveen kumar thotapraveen kumar thota
If i can see your code completely then i can resolve this problem.
Dharmendra PahadiyaDharmendra Pahadiya
<!---
    DESCRIPTION: This page is overridden for NEW and EDIT operation on tRIIO Activity. This has been done to embed the AutoComplete
                 Gazetteer component in the page. 
                   
--->
<apex:page StandardController="tRIIO_Activity__c"  tabstyle="tRIIO_Activity__c" extensions="tRIIO_Activity_Override"  id="myPage" action="{!editOverride}">
    <script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
    <script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
    <script type="text/javascript">
        window.onload = function(e){ 
            window.scroll(0,1500); // horizontal and vertical scroll targets
            //document.getElementById("myPage:myForm:pageBlock:pbSection6:Comments").focus();
            var a=document.getElementById("myPage:myForm:pageBlock:pbSection4:notification_type");
            var str = a.options[a.selectedIndex].text;
            //alert(str);
               showConditionSection(str);    
        }
       
        function showConditionSection(notificationType){
          var panel = document.getElementById('conditionalPanel');
          if(notificationType == 'Permit'){
            panel.style.display ='';
          }
          else{
            panel.style.display = 'none';
          }
        }
    </script>   
    <apex:sectionHeader title="tRIIO Activity" subtitle="Edit tRIIO Activity"/>
    <apex:pageMessages id="pgMsg"></apex:pageMessages>
    <apex:form id="myForm">
        <input type="hidden" id="USRN" name="USRN" value = "myPage:myForm:pageBlock:pbSection4:usrn"/>
        <input type="hidden" id="Street" name="Street" value = "myPage:myForm:pageBlock:pbSection4:street"/>
        <input type="hidden" id="Locality" name="Locality" value = "myPage:myForm:pageBlock:pbSection4:locality"/>
        <input type="hidden" id="Town" name="Town" value = "myPage:myForm:pageBlock:pbSection4:town"/>
        <input type="hidden" id="County" name="County" value = "myPage:myForm:pageBlock:pbSection4:county"/>
        <input type="hidden" id="roadclass" name="roadClass" value = "myPage:myForm:pageBlock:pbSection4:roadClassSec:roadclass"/>
        <input type="hidden" id="eastStart" name="eastStart" value = "myPage:myForm:pageBlock:pbSection3:easting1"/>
        <input type="hidden" id="eastEnd" name="eastEnd" value = "myPage:myForm:pageBlock:pbSection3:easting2"/>
        <input type="hidden" id="northStart" name="northStart" value = "myPage:myForm:pageBlock:pbSection3:northing1"/>
        <input type="hidden" id="northEnd" name="northEnd" value = "myPage:myForm:pageBlock:pbSection3:northing2"/>
        <apex:pageBlock title="tRIIO Activity" mode="edit" id="pageBlock"> 
            <apex:pageBlockButtons > 
                <!-- MY Change -->
                <apex:actionStatus id="mySaveStatus1">
                     <apex:facet name="stop">     
                           <apex:commandButton action="{!saveOverride}" status="mySaveStatus1" value="Save" disabled="false" rerender="pgMsg"/>     
                     </apex:facet>     
                     <apex:facet name="start">
                        <apex:commandButton status="mySaveStatus1" value="Saving..." disabled="true"/>                     
                     </apex:facet>
                </apex:actionStatus>
                <!-- <apex:commandButton value="Save" onclick="document.getElementById('myPage:myForm:pageBlock:pbSection4:roadclass').disabled =false;" action="{!saveOverride}"/>-->
                <!-- MY Change -->
                <apex:commandButton value="Cancel" action="{!cancel}"/> 
            </apex:pageBlockButtons>
            <apex:panelgrid columns="3" cellpadding="10" >
                <apex:outputLabel ><b>Search for Street / Town / Location </b> </apex:outputLabel>
                <apex:inputText style="height:19px" size="60" id="gazSearch">
                    <c:gazetteerAutoComplete autocomplete_textbox="{!$Component.gazSearch}" 
                        localityTxtBoxId="myPage:myForm:pageBlock:pbSection4:locality"
                        streetTxtBoxId="myPage:myForm:pageBlock:pbSection4:street"
                        townTxtBoxId="myPage:myForm:pageBlock:pbSection4:town"
                        usrnTxtBoxId="myPage:myForm:pageBlock:pbSection4:usrn"
                        countyTxtBoxId="myPage:myForm:pageBlock:pbSection4:county"
                        roadClassTxtBoxId="myPage:myForm:pageBlock:pbSection4:roadclass"
                        e1TxtBoxId="myPage:myForm:pageBlock:pbSection3:easting1"
                        n1TxtBoxId="myPage:myForm:pageBlock:pbSection3:northing1"
                        e2TxtBoxId="myPage:myForm:pageBlock:pbSection3:easting2"
                        n2TxtBoxId="myPage:myForm:pageBlock:pbSection3:northing2"
                        coordinatesTxtBoxId="myPage:myForm:pageBlock:HiddenInfoSection:coordinateItem:coordinate"
                        trafficsensitiveTxtBoxId="myPage:myForm:pageBlock:HiddenInfoSection:trafficsensitiveItem:TrafficSensitive"
                    />
                </apex:inputText>
                <apex:commandButton style="height:25px" onclick="opendetails();return false;" value="Street Details" />
            </apex:panelgrid> 
            <apex:pageBlockSection title="Status" columns="2" id="pbSection1" >
                <apex:inputField value="{!tRIIO_Activity__c.Activity_Status__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Status__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Original_Activity__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Cancelled__c}" id="chkCancelled" />
                <apex:inputField value="{!tRIIO_Activity__c.Closure_Report__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Cancellation_Reason__c}" id="CancelledReason"/>
                <apex:inputField value="{!tRIIO_Activity__c.NG_Contact__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Abandoned__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.NG_Contact_Number__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Abandon_Reason__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Schedule__c}"/> 
                <apex:inputField value="{!tRIIO_Activity__c.D_42__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Activity_Type__c}" required="true"/> <!-- CH014 -->
            </apex:pageBlockSection>
        <!-- CH014.Starts -->
            <apex:pageBlockSection title="Letters" columns="2">
                <apex:inputfield value="{!tRIIO_Activity__c.Advanced_Letters_Sent__c}"/>
                <apex:outputLabel />
                <apex:inputfield value="{!tRIIO_Activity__c.X10_Days_Letters_Sent__c}"/>
                <apex:inputfield value="{!tRIIO_Activity__c.X10_Days_Letters_Delivery_Method__c}"/>
            </apex:pageblocksection>
        <!-- CH014.End -->     
        <!-- CH012 Starts -->            
             <apex:pageBlockSection title="DCT Information" columns="2" id="pbSection8" >
                <apex:inputField value="{!tRIIO_Activity__c.DCT_Activity__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Pack_Status__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Pack_Type__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.DCT_Comments__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Abandonment_in_Pack_m_Activity__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Pack_Required_for_Notice__c}"/>
            </apex:pageBlockSection>
        <!-- CH012 End-->   
            <apex:pageBlockSection title="Description" columns="2" id="pbSection2">
                <apex:inputField value="{!tRIIO_Activity__c.Works_Order__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Project__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Est_Inspection_Units__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Notice_Requested_By__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Date_Requested__c}" /> 
                <apex:inputField value="{!tRIIO_Activity__c.NOM_COM_Authorisation__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.FLM_Code__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Telephone_No__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Duration__c}" />
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Detailed Description" columns="2" id="pbSection4">
                <apex:inputField value="{!tRIIO_Activity__c.Mains_Work_Description__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Reinst_Request_No__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Location_of_works__c}" required="true"/>
                <apex:inputField value="{!tRIIO_Activity__c.NRSWA_No__c}" />
                <apex:inputField id="street" value="{!tRIIO_Activity__c.Street__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Notice_Type__c}" />
                <apex:inputField id="locality" value="{!tRIIO_Activity__c.Locality__c}"/>
                <apex:inputField id="notification_type" value="{!tRIIO_Activity__c.Notification_Type__c}" required="true" onchange="showConditionSection(this.value)"/> 
               <!-- Commented by Siva for SR_tRIIO_180 <apex:inputField id="notification_type" value="{!tRIIO_Activity__c.Notification_Type__c}" required="true" />-->
                <apex:inputField id="town" value="{!tRIIO_Activity__c.Town__c}" />
                <apex:inputField id="usrn" value="{!tRIIO_Activity__c.USRN__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Post_Code__c}" />
                <apex:inputField id="roadclass" value="{!tRIIO_Activity__c.Road_Class__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.County__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Traffic_Management__c}" />
                <apex:inputField id="county" value="{!tRIIO_Activity__c.Local_Authority__c}" />
                <!-- CH09.start -->
                <apex:inputField value="{!tRIIO_Activity__c.Traffic_Sensitive_check__c}" /> 
                <apex:inputField value="{!tRIIO_Activity__c.Lane_Rental__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Spoil_on_site__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.NG_District__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Barriers_on_site__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.District__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Traffic_Lights_on_site__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Reinstatement_Capture_By__c}"/><!-- CH013 -->
                <apex:inputField value="{!tRIIO_Activity__c.Ongoing__c}"/>
<!--CH06 # SR_tRIIO_075  <apex:inputField value="{!tRIIO_Activity__c.Zone__c}"/>   -->
                <apex:inputHidden value="{!tRIIO_Activity__c.h_Temp_Usrn__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Final_form__c}"/>  <!-- CH07 -->
                <apex:outputLabel /><!-- adding one space -->
                <apex:inputField value="{!tRIIO_Activity__c.Heavy_Lift_Operation__c}"/>  <!-- CH04# -->
                <!-- CH09.end -->
                <!-- CH05.Start -->
                    <apex:outputLabel /><!-- adding one space -->
                    <apex:inputField value="{!tRIIO_Activity__c.Urgent_Response__c}" />
                <!-- CH05.End -->
            </apex:pageBlockSection>

            <!--CH02.Start-->
            <apex:pageBlockSection id="HiddenInfoSection" columns="2">    
                <apex:pageBlockSectionItem id="coordinateItem">
                    <apex:inputHidden value="{!tRIIO_Activity__c.h_Street_Coordinate__c}" id="coordinate" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem id="trafficsensitiveItem"> 
                    <apex:inputHidden value="{!tRIIO_Activity__c.Traffic_Sensitive__c}" id="TrafficSensitive"/>
                </apex:pageBlockSectionItem> 
            </apex:pageBlockSection>    
            <!--CH02.End-->
            
            <apex:pageBlockSection title="Grid Reference" columns="2" id="pbSection3">
                <apex:inputField id="easting1" value="{!tRIIO_Activity__c.Eastings_Start__c}"  />
                <apex:inputField id="northing1" value="{!tRIIO_Activity__c.Northings_Start__c}" />
                <apex:inputField id="easting2" value="{!tRIIO_Activity__c.Eastings_End__c}" />
                <apex:inputField id="northing2" value="{!tRIIO_Activity__c.Northings_End__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Permit details" columns="2" id="pbSection10" rendered="{!if(NOT(OR(contains($Profile.Name,'NGA Sub Reinstator'),contains($Profile.Name,'Sub Reinstator (EDF, NG)'))),true,false)}">
                <apex:inputField id="paaPermitSts" value="{!tRIIO_Activity__c.PAA_Permit_Status__c}"/>
                <apex:inputField id="paPermitSts" value="{!tRIIO_Activity__c.PA_Permit_Status__c}"/>
                <apex:inputField id="paaPermitStsDate" value="{!tRIIO_Activity__c.PAA_Permit_Status_Date__c}"/>
                <apex:inputField id="paPermitStsDate" value="{!tRIIO_Activity__c.PA_Permit_Status_Date__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Works Details" columns="2" id="pbSection6">
                <apex:inputField id="Estimated_Start" value="{!tRIIO_Activity__c.Estimated_Start__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Estimated_End__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Works_Start_Date__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Works_End_Date__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Received__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Required_Completion__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Actual_Start__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Works_Close__c}" />
                <apex:inputField value="{!tRIIO_Activity__c.Date_to_Reinstators__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.DaysbetweenFirstWorksEndDateandReceived__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Site_Clear__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.DaysbetweenWorksEndDateandReceived__c}"/>
                <apex:inputField value="{!tRIIO_Activity__c.Registration__c}"/>
                <apex:inputField id="Comments" value="{!tRIIO_Activity__c.Comments__c}"/>    
            </apex:pageBlockSection>
            
            <!--Ch11.start  -->
           
            <div id="conditionalPanel" style="display:none;">
               <apex:pageBlockSection title="Permit Conditions" columns="2" id="pbSection7">
                    <apex:inputField value="{!tRIIO_Activity__c.Time_Constraints__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.Date_Constraints__c}"  />
                    <apex:inputField value="{!tRIIO_Activity__c.Out_of_Hours_Work__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.Material_and_Plant_Storage__c}"  />
                    <apex:inputField value="{!tRIIO_Activity__c.Road_Occupation_Dimensions__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.Traffic_Space_Dimensions__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.Road_Closure__c}"  />
                    <apex:inputField value="{!tRIIO_Activity__c.Light_Signals_and_Shuttle_Working__c}"  />
                    <apex:inputField value="{!tRIIO_Activity__c.Traffic_Management_Changes__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.Work_Methodology__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.Consultation_and_Publicity__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.Environmental__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.Local__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.No_Conditions_Supplied__c}" />
                    <apex:inputField value="{!tRIIO_Activity__c.Condition_Text__c}" />   
               </apex:pageBlockSection>
            </div>
            <!--Ch11.end  -->
        </apex:pageBlock>
        
    </apex:form>
    <!--Ch01.start  -->
    <script>
        if(!('{!$Profile.Name}'=="System Administrator" || '{!$Profile.Name}'=="NGA Administrator" )){
        document.getElementById("myPage:myForm:pageBlock:pbSection1:chkCancelled").disabled =true;
        document.getElementById("myPage:myForm:pageBlock:pbSection1:CancelledReason").disabled =true;
        }
        document.getElementById("myPage:myForm:pageBlock:pbSection4:roadclass").disabled =true;
        var panel = document.getElementById('conditionalPanel');
        if(currentValue.value == 'Permit'){
            panel.style.display ='';
          }
          else{
            panel.style.display = 'none';
          }
    </script>
    <!--Ch01.End-->
</apex:page>

The above is the page which we are using on Create and Edit. We are calling a web service from a custom component.
I have checked the debug logs and found that While saving a record if a custom validation error occurs then it will not exit and again save method will be called and throws error.
Why it is calling Save method second time after Validation fires? Please help.