Print this page

Conditionally rendering fields on visualforce page based on picklist values

Knowledge Article Number 000003854
Description

Below example helps you to render a VF page based on a criteria

Resolution
<apex:pageBlock id="xxxpb1">

<apex:pageBlockSection>
                    
<apex:actionRegion >               

  <apex:inputField id="xxxif1" value="{!Object.picklistfieldapiname1}" required="true" >

     <apex:actionSupport event="onchange" rerender="xxxpb1" />
  </apex:inputField>

</apex:actionRegion>
                 
</apex:pageBlockSection>
               
<apex:pageBlockSection id="xxxpbs1" rendered="true">

 <apex:inputField id="xxxif2" value="{!Object.Fieldtobedisplayed1}" rendered="{!IF(Object.picklistfieldapiname1 ='picklist value 1' || lead.Buyer_Type__c ='picklist value 2' ,true,false)}"/>

</apex:pageBlockSection>

<apex:pageBlockSection id="xxxpbs2" rendered="true">

  <apex:inputField id="xxxif3" value="{!Object.Fieldtobedisplayed2}" rendered="{!IF(Object.picklistfieldapiname1 ='picklist value 3' || lead.Buyer_Type__c ='picklist value 4' ,true,false)}"/>  
                                                                     
</apex:pageBlockSection>

</apex:PageBlock>

In the above code block, fields are displayed on VF page only if the rendering criteria is met.




promote demote