How to show or hide a particular section of Visualforce Page dependent upon picklistfield value

In this example, I am going to explain that how to show/hide a particular section of Vf Page that depends on a picklist field value i.e. for a specific picklist value you are showing/hiding a particular part of a VF Page.

This can be achieved by using both the Standard Controller and as well as Custom controller functionality.

Here I am using Standard Controller functionality.

VF Page---

<
<apex:page standardController="Contact">
  <apex:form id="frm">
      <apex:pageBlock >
          <apex:pageBlockSection >
              <apex:inputField value="{!contact.LeadSource}">
                  <apex:actionSupport event="onchange" reRender="frm"/>
              </apex:inputField>
           </apex:pageBlockSection>     
      </apex:pageBlock>
      
      <apex:pageBlock rendered="{!IF(contact.LeadSource == 'Web', true , false)}">     
          <apex:pageBlockSection >
          
              <apex:inputField value="{!contact.FirstName}"/>
              <apex:inputField value="{!contact.Lastname}"/>
              <apex:inputField value="{!contact.Title}"/>
              
          </apex:pageBlockSection>      
      </apex:pageBlock>
      
      <apex:pageBlock rendered="{!IF(contact.LeadSource == 'Phone Inquiry', true, false)}">         
          <apex:pageBlockSection >
          
              <apex:inputField value="{!contact.Phone}"/>
              <apex:inputField value="{!contact.HomePhone}"/>
              <apex:inputField value="{!contact.OtherPhone}"/>
              <apex:inputField value="{!contact.MobilePhone}"/>
              <apex:inputField value="{!contact.AssistantPhone}"/>
              <apex:inputField value="{!contact.Fax}"/>
              
          </apex:pageBlockSection>     
      </apex:pageBlock>
      
      <apex:pageBlock rendered="{!IF(contact.LeadSource == 'Other', true, false)}">        
          <apex:pageBlockSection >
          
              <apex:inputField value="{!contact.MailingCountry}"/>
              <apex:inputField value="{!contact.MailingStreet}"/>
              <apex:inputField value="{!contact.MailingCity}"/>
              <apex:inputField value="{!contact.MailingState}"/>
              <apex:inputField value="{!contact.OtherStreet}"/>
              <apex:inputField value="{!contact.OtherCity}"/>
              
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>

</apex:page>

And output looks like this--

Comments

Popular posts from this blog

Dynamically Add/Delete rows in Visualforce Page

Process Automation Specialist Superbadge