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
Raghavendra ARaghavendra A 

VF Tag condition help

Hi All,

I am trying to render few fields based on the value of a picklist field. When the value of Picklist is changed to Old then only fields A, B, C must be shown. When the Value of Picklist is changed to New then all 5 fields A,B,C,D, E must be shown. Please help me on how to show two different conditions in Visualforce page tag for a Picklist field. 

Following is the code.

 <apex:inputField value="{!A}"  rendered="{!Picklist == 'New'}"/>
  <apex:inputField value="{!B}" rendered="{!Picklist == 'New'}"/>
   <apex:inputField value="{!C}"  rendered="{!Picklist == 'New'}"/>
  <apex:inputField value="{!D}" rendered="{!Picklist == 'New'}"/>
   <apex:inputField value="{!E}"  rendered="{!Picklist == 'New'}"/>
 
I was able to show all 5 fields when Picklist value is New. How can I add anther condition? Any help would be highly appreciated.

Thanks,
Raghu

 
Best Answer chosen by Raghavendra A
Chidambar ReddyChidambar Reddy
<apex:inputField value="{!A}"  rendered="{!OR(Picklist == 'New',Picklist=='Old')}"/>
  <apex:inputField value="{!B}" rendered="{!OR(Picklist == 'New',Picklist=='Old')}"/>
   <apex:inputField value="{!C}"  rendered="{!OR(Picklist == 'New',Picklist=='Old')}"/>
  <apex:inputField value="{!D}" rendered="{!Picklist == 'New'}"/>
   <apex:inputField value="{!E}"  rendered="{!Picklist == 'New'}"/>

Try this, if you have more than 2 picklist values, or if you don't want to show any of the field when picklist is blank

Otherwise the previous solution will work

All Answers

Chidambar ReddyChidambar Reddy
<apex:inputField value="{!A}" />
  <apex:inputField value="{!B}"/>
   <apex:inputField value="{!C}"/>
  <apex:inputField value="{!D}" rendered="{!Picklist == 'New'}"/>
   <apex:inputField value="{!E}"  rendered="{!Picklist == 'New'}"/>
Try the above code
Chidambar ReddyChidambar Reddy
<apex:inputField value="{!A}"  rendered="{!OR(Picklist == 'New',Picklist=='Old')}"/>
  <apex:inputField value="{!B}" rendered="{!OR(Picklist == 'New',Picklist=='Old')}"/>
   <apex:inputField value="{!C}"  rendered="{!OR(Picklist == 'New',Picklist=='Old')}"/>
  <apex:inputField value="{!D}" rendered="{!Picklist == 'New'}"/>
   <apex:inputField value="{!E}"  rendered="{!Picklist == 'New'}"/>

Try this, if you have more than 2 picklist values, or if you don't want to show any of the field when picklist is blank

Otherwise the previous solution will work
This was selected as the best answer
Raghavendra ARaghavendra A
Hi, Thanks for the reply. But this set of fields has several other fields and Initially the picklist value will be none when the visualforce page is loaded. When the picklist value is none then no fields should be displayed. Thanks, Raghu
Chidambar ReddyChidambar Reddy
Hi Raghu,

I guess, the next solution will work for you