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
Dhananjaya BulugahamulleDhananjaya Bulugahamulle 

Hide a button on click

I want to hide my save button (id="c2") when some one click one the edit button. i tried using j query, but it does not work. Does anybody have any idea? Thanks
 
<apex:pageblockButtons >
    <apex:commandButton action="{!doToggleEditMode}" value="Edit" reRender="myPanel" rendered="{!NOT(bEditMode)}" id="c1" />
    <apex:commandButton action="{!doSave}" value="Save" reRender="myPanel" rendered="{!bEditMode}" />
    <apex:commandButton value="PRINT" onclick="window.print();"/>
    <apex:commandButton value="Cancel" action="{!Cancel}"/>
    <apex:commandButton value="Save" action="{!save}" id="c2"/>
</apex:pageblockButtons>

Extension
 
public Boolean bEditMode {
get {
  if(bEditMode == null) {
      bEditmode = false;
      }
      return bEditMode;
  }
  set;
}

public PageReference doToggleEditMode() {
     bEditMode = !bEditMode;
        return null;
}

public PageReference doSave() {
    try {
    controller.save();
    doToggleEditMode();
    }
    catch(Exception ex) {
    }

    return null;
}

 
Best Answer chosen by Dhananjaya Bulugahamulle
Anupam RastogiAnupam Rastogi
Okay so in that case you can use the rendered attribute like this
<apex:pageblockButtons >
    <apex:commandButton action="{!doToggleEditMode}" value="Edit" reRender="myPanel" rendered="{!NOT(bEditMode)}" id="c1" />
    <apex:commandButton action="{!doSave}" value="Save" reRender="myPanel" rendered="{!bEditMode}" />
    <apex:commandButton value="PRINT" onclick="window.print();"/>
    <apex:commandButton value="Cancel" action="{!Cancel}"/>
    <apex:commandButton value="Save" action="{!save}" id="c2" rendered="{! bEditMode }"/>
</apex:pageblockButtons>

Thanks
AR

If you found this reply useful then please mark it as best answer.

All Answers

Anupam RastogiAnupam Rastogi
Hi Dhananjaya,

Why are you having two Save buttons?

Thanks
AR
Dhananjaya BulugahamulleDhananjaya Bulugahamulle
No it a toggle button. When you click on the edit it will chnage to save. In that case i have two save button and i want to hide one of them. 
 
Grace Patiño PérezGrace Patiño Pérez
Hi!
does the button "c2" inside "myPanel"? because is the only thing that can change with the action of the buttons.
I hope it help! :)
Anupam RastogiAnupam Rastogi
Okay so in that case you can use the rendered attribute like this
<apex:pageblockButtons >
    <apex:commandButton action="{!doToggleEditMode}" value="Edit" reRender="myPanel" rendered="{!NOT(bEditMode)}" id="c1" />
    <apex:commandButton action="{!doSave}" value="Save" reRender="myPanel" rendered="{!bEditMode}" />
    <apex:commandButton value="PRINT" onclick="window.print();"/>
    <apex:commandButton value="Cancel" action="{!Cancel}"/>
    <apex:commandButton value="Save" action="{!save}" id="c2" rendered="{! bEditMode }"/>
</apex:pageblockButtons>

Thanks
AR

If you found this reply useful then please mark it as best answer.
This was selected as the best answer