0

I have Vf page on Opportunity with custom controller. I need to make fields visible only after checkbox is checked. here is my code . something is missing . i'm getting fields hide all time.

Vf Page

<apex:page standardController="Opportunity" extensions="opportunityOrderDetail">
  <apex:form >
      <apex:pagemessages /> 
    <apex:pageBlock title="Opportunity details">
    <apex:pageBlockSection title="Opportnuity Infromation" >
        <apex:inputField value="{! Opportunity.OwnerId }"/>
        <apex:inputField value="{! Opportunity.Amount }"/>
        <apex:inputField value="{! Opportunity.IsPrivate }"/>
        <apex:inputField value="{! Opportunity.CloseDate }"/>
        <apex:inputField value="{! Opportunity.Name }"/>    
        <apex:inputField value="{! Opportunity.NextStep}"/>
        <apex:inputField value="{! Opportunity.Account.Name }"/>
        <apex:inputField value="{! Opportunity.StageName }"/>
        <apex:inputField value="{! Opportunity.Type }"/>
        <apex:inputField value="{! Opportunity.Probability }"/>
        <apex:inputField value="{! Opportunity.LeadSource }"/>
        <apex:inputField value="{! Opportunity.CampaignId}"/>
        <apex:inputField value="{! Opportunity.Status__c }"/>
        <apex:inputField value="{! Opportunity.Primary_Customer_Email_Id__c}"/>
        <apex:inputField value="{! Opportunity.Primary_Competitor__c }"/>



    </apex:pageBlockSection>
    <apex:pageBlockSection title="Additional Information" >
        <apex:inputCheckbox value="{!Opportunity.Order_Details__c}" onchange="{!click}"  />
         <apex:actionSupport event="onchange" reRender="thePanel" action="{!click}"/> 
          <apex:pageBlockSection title="Order Details" id="OrderDetails" rendered="{!displayInputputText}">           
        <apex:inputField value="{! Opportunity.OrderNumber__c }" /> 
        <apex:inputField value="{! Opportunity.MainCompetitors__c }"/> 
        <apex:inputField value="{! Opportunity.CurrentGenerators__c }" />
        <apex:inputField value="{! Opportunity.DeliveryInstallationStatus__c }" />
        <apex:inputField value="{! Opportunity.TrackingNumber__c }" /> 
        </apex:pageBlockSection>
        </apex:pageBlockSection>

     <apex:pageBlockSection title="Description Information" >
         <apex:inputField value="{! Opportunity.Description }"/> <br/>
         <apex:inputField value="{! Opportunity.Reason_for_Rejection__c}"/> 

         </apex:pageBlockSection>




        <apex:pageBlockButtons >

        <apex:commandButton action="{!save}" value="save"/>
        <apex:commandButton action="{!save}" value="Save & New"/>
        <apex:commandButton action="{!cancel}" value="cancel"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>


  </apex:form>

</apex:page>

Here is My Custom Controller

 public class opportunityOrderDetail {
    public Opportunity oppty{get;set;}

     public Boolean displayInputputText{get;set;}

    public  opportunityOrderDetail(ApexPages.StandardController controller){
        oppty=(Opportunity)controller.getRecord();}


    public PageReference click(){    
         if(oppty.Order_Details__c==true){
             displayInputputText = true;
         }
         else{
             displayInputputText = false;
         }
         return null;
     }
}
0

Rendering fields on click of checkbox is always a tedious job. Here is a small example were I rendered one inputtext when user checks the checkbox.

VF page:

<apex:outputPanel id="panel1">
    Check to show textbox:
    <apex:inputCheckbox value="{!check}" >

        <apex:actionsupport event="onchange" rerender="panel2" />
    </apex:inputCheckbox>
</apex:outputPanel>
<br/>
<apex:outputPanel id="panel2" >
    <apex:inputtext label="Enter value" value="{!checkText}" rendered="{!check}"/>

</apex:outputPanel><br/>

Controller:

public boolean check{get;set;}
public string checkText{get;set;}

If you want to populate any data into those fields then you can add action attribute to actionSupport.

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.