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
RReddyRReddy 

On Clicking Save button, Cancel button also need to go into Saving mode

Hi, I designed a VF page with save and cancel buttons . On Clicking Save button, Cancel button also need to go into Saving mode, similar to Salesforce standard page.

 

My Requirement is :

 

On Clicking Save Button we should disble both Save & Cancel buttons and need to show saving text for both buttons

 

Thanks,

Ramana

Best Answer chosen by Admin (Salesforce Developers) 
vishal@forcevishal@force

Try this, it will disable both the buttons and it will show the text as 'saving...' on both of them.

 

 

<apex:pageBlock >
            <apex:commandButton value="Save" id="save" action="{!save}" onclick="saving('start', this, '{!$Component.cancel}');" oncomplete="saving('stop', this, '{!$Component.cancel}');"/>
            <apex:commandButton value="Cancel" id="cancel" action="{!cancel}" />
                <script>
                    function saving(activity, obj, id)
                    {
                         if(activity == 'start'){
                             obj.value = 'saving...';
                             obj.disabled=true;
                             document.getElementById(id).value = 'saving...';
                             document.getElementById(id).disabled = true;
                         }
                         else{
                             obj.value = 'save';
                             obj.disabled=false;
                             document.getElementById(id).value = 'cancel';
                             document.getElementById(id).disabled = false;
                         }
                        
                    }
                </script>
 </apex:pageBlock>

All Answers

sravan alaparthisravan alaparthi

Dear Reddy,

 

if i got it correct u want disable cancel button once Save button is clicked...

 

for this you can rerender the buton's section or panel where your buttons reside when the save button is clicked...

 

Some tips would be:

 

1)Use onclick event for save button

2)reRender the buttons section with attribute disabled is true  for cancel button  

 

Sravan Alaparthi

Salesforce Developer/Adminstrator

RReddyRReddy

Thanks Sravan,

 

The below code is working for save.but i want to disable cancel and show saving text for both the buttons(Save and Cancel) when i clicked on Save button. 

 

 

<apex:pageBlockButtons location="bottom">

        <apex:actionStatus id="leadActivityTypeStatus">
        <apex:facet name="stop"> 
            <apex:commandButton value="{!$Label.save}" action="{!saveLeadActivityType}" onclick="this.disabled=true;"
                                                    disabled="false" rerender="Form" status="leadActivityTypeStatus"/>
        </apex:facet>
        <apex:facet name="start">
             <apex:commandButton status="leadActivityTypeStatus" value="{!$Label.saving}" disabled="true" />
         </apex:facet>
       </apex:actionStatus>

<apex:CommandButton value="{!$Label.cancel}" action="{!closePanel}"/>

 

</apex:pageBlockButtons>

 

 

Thanks

Ramana

vishal@forcevishal@force

Try this, it will disable both the buttons and it will show the text as 'saving...' on both of them.

 

 

<apex:pageBlock >
            <apex:commandButton value="Save" id="save" action="{!save}" onclick="saving('start', this, '{!$Component.cancel}');" oncomplete="saving('stop', this, '{!$Component.cancel}');"/>
            <apex:commandButton value="Cancel" id="cancel" action="{!cancel}" />
                <script>
                    function saving(activity, obj, id)
                    {
                         if(activity == 'start'){
                             obj.value = 'saving...';
                             obj.disabled=true;
                             document.getElementById(id).value = 'saving...';
                             document.getElementById(id).disabled = true;
                         }
                         else{
                             obj.value = 'save';
                             obj.disabled=false;
                             document.getElementById(id).value = 'cancel';
                             document.getElementById(id).disabled = false;
                         }
                        
                    }
                </script>
 </apex:pageBlock>

This was selected as the best answer
ram.svkp@gmail.comram.svkp@gmail.com

Thank you Vishal...You did a gr8 job..Its working for me.