+ Start a Discussion
SujanSaiSujanSai 

Hiding thebuttons

Hi.

Another post..
I need 2page block button,while working o one theotherhas to be disabled.. How to achieve this?
Please help.
Thanks, 
Sujan
Best Answer chosen by SujanSai
DeepthiDeepthi (Salesforce Developers) 
Hi,

Please refer the below code snippet.
 
<apex:page controller="ControllerClass">
<apex:form >
        Enter First Value &nbsp;&nbsp;<apex:inputText value="{!a}"/> <br/>
        Enter Second Value &nbsp;&nbsp;<apex:inputText value="{!b}"/><br/>
        <apex:commandButton value="Add" action="{!value1}" rendered="{!v1}"/>
        <apex:commandButton value="Subtract" action="{!value2}" rendered="{!v2}"/>
        <apex:commandButton value="Multiply" action="{!value3}" rendered="{!v3}"/><br/>
        <apex:outputText value="{!res}"/>
</apex:form>
</apex:page>
 
public class ControllerClass {

    public Integer res { get; set; }

    public Integer b { get; set; }

    public Integer a { get; set; }

    public Boolean v1 { get; set; }
    
    public Boolean v2 { get; set; }
    
    public Boolean v3 { get; set; }
    public ControllerClass (){
        v1=true;
        v2=true;
        v3=true;
    }
    
    public PageReference value1() {
        v1=false;
        v2=true;
        v3=true;
        res=a+b;
        return null;
    }


    public PageReference value2() {
        v2=false;
        v1=true;
        v3=true;
        res=a-b;
        return null;
    }

    public PageReference value3() {
        v3=false;
        v1=true;
        v2=true;
        res=a*b;
        return null;
    }
    
}

Hope this helps you!
Best Regards,
Deepthi

All Answers

Himanshu Jasuja 9Himanshu Jasuja 9
Hi surya,
You can use disabled=true in your apex tag. 
1)
<apex:commandButton value="Processing..." status="newStatus" disabled="true"/> >

2) you can also use javascript for disablibg button.

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>

Let me knows if its helps you.
DeepthiDeepthi (Salesforce Developers) 
Hi,

Please refer the below code snippet.
 
<apex:page controller="ControllerClass">
<apex:form >
        Enter First Value &nbsp;&nbsp;<apex:inputText value="{!a}"/> <br/>
        Enter Second Value &nbsp;&nbsp;<apex:inputText value="{!b}"/><br/>
        <apex:commandButton value="Add" action="{!value1}" rendered="{!v1}"/>
        <apex:commandButton value="Subtract" action="{!value2}" rendered="{!v2}"/>
        <apex:commandButton value="Multiply" action="{!value3}" rendered="{!v3}"/><br/>
        <apex:outputText value="{!res}"/>
</apex:form>
</apex:page>
 
public class ControllerClass {

    public Integer res { get; set; }

    public Integer b { get; set; }

    public Integer a { get; set; }

    public Boolean v1 { get; set; }
    
    public Boolean v2 { get; set; }
    
    public Boolean v3 { get; set; }
    public ControllerClass (){
        v1=true;
        v2=true;
        v3=true;
    }
    
    public PageReference value1() {
        v1=false;
        v2=true;
        v3=true;
        res=a+b;
        return null;
    }


    public PageReference value2() {
        v2=false;
        v1=true;
        v3=true;
        res=a-b;
        return null;
    }

    public PageReference value3() {
        v3=false;
        v1=true;
        v2=true;
        res=a*b;
        return null;
    }
    
}

Hope this helps you!
Best Regards,
Deepthi
This was selected as the best answer
ManojjenaManojjena
Hi suryasujansai kotaprolu,
Still we need bit more clarity on this ,Assume you have button A and B .On load of page both should visible or one then which one ? Please clarify so that we can give you solution .
JyothsnaJyothsna (Salesforce Developers) 
Hi Surya,

Please refer the below sample code (e.g:Online exam questions).

Visualforce Page
<apex:page controller="HideShowController">
 <apex:form >
  <apex:pageBlock >
  <apex:pageBlockSection >
  1.question?
  <apex:pageBlockSectionItem >
 <apex:commandButton action="{!answer}" value="YES" rendered="{!answer}"></apex:commandButton>
  <apex:commandButton action="{!skipquest}" value="NEXT" rendered="{!nextquest}"></apex:commandButton>
</apex:pageBlockSectionItem>
      <apex:outputLabel rendered="{!solution}">answer1</apex:outputLabel>
 </apex:pageBlockSection>
 <apex:pageBlockSection >
 <apex:outputLabel rendered="{!quest2}">2.question</apex:outputLabel>
  <apex:pageBlockSectionItem >
 <apex:commandButton action="{!answer1}" value="YES" rendered="{!answer1}" ></apex:commandButton>
  <apex:commandButton action="{!skipquest1}" value="NEXT" rendered="{!nextquest1}" ></apex:commandButton>
</apex:pageBlockSectionItem>

<apex:outputLabel rendered="{!solution2}">answer2</apex:outputLabel>
 </apex:pageBlockSection>
 </apex:pageblock>
 </apex:form>
 </apex:page>

Controller
 
public with sharing class HideShowController {


    public boolean solution2 { get; set; }

    public boolean quest2 { get; set; }

    public boolean solution1 { get; set; }

    public boolean solution { get; set; }

    public boolean nextquest1 { get; set; }

    public boolean answer1 { get; set; }

    
   
    public Boolean nextquest { get; set; }
    
     public Boolean answer { get; set; }

   public HideShowController(){
      answer=true;
      nextquest=true;
      solution=false;
      quest2=false;
      solution2=false;
     
     
   }
    public PageReference skipquest() {
       answer=false;
       nextquest1=true;
       quest2=true;
       nextquest=false;
       answer1=true;
       
        return null;
    }


    public PageReference answer() {
       solution=true;
       answer=false;
        return null;
    }

   
    public PageReference skipquest1() {
        return null;
    }


    public PageReference answer1() {
        solution2=true;
       answer1=false;
       
        return null;
    }


 
}

Hope this helps you!
Best Regards,
Jyothsna