+ Start a Discussion
elkid_24elkid_24 

VF Page - Hide/Show fields based on lookup field

Is there a way to hide or show a section/fields based on a lookup field? I currently have a lookup field that returns 1 of 4 names. I'd like to render and/or hide sections based on the name in the lookup field.
<b><!-- Activity 1  Show this section if lookup field name = Activity 1--></b>
<apex:pageBlockSection title="Activity 1">
<apex:outputField value="{!CEQ__c.Field1__c}"/> 
<apex:outputField value="{!CEQ__c.Field2__c}"/>        
</apex:pageBlockSection>                        
                        
<b><!-- Activity 2  Show this section if lookup field name = Activity 2--></b>
<apex:pageBlockSection title="Activity 2">
<apex:outputField value="{!CEQ__c.Field3__c}"/> 
<apex:outputField value="{!CEQ__c.Field4__c}"/>        
</apex:pageBlockSection>

I am on Profession Edition and can't use any controllers. Any help would be greatly appreciated. 
karthikeyan perumalkarthikeyan perumal
Hello elkid_24

Use below code in your Section/Field rendered tag. 

if you want  to Check for spacific 1 Name use Below, 
rendered="{!IF(Object.picklistfieldapiname ='Name',true,false)}"
else  if you want use OR condition for multiple names use below 
 
rendered="{!IF(Object.picklistfieldapiname ='Name1' || Object.picklistfieldapiname ='Name2' || Object.picklistfieldapiname ='Name3',true,false)}"

Hope it will help you. MARK BEST ANSWER  if its work for you. 

Thanks
Karthik

 
elkid_24elkid_24
Hello, 

Thank you for your response. I appreciate it. Would you apply the rendered if statement at the end of the output line like this:
 
<b><!-- Activity 1  Show this section if lookup field name = Activity 1--></b>
<apex:pageBlockSection title="Activity 1">
<apex:outputField value="{!CEQ__c.Field1__c}" rendered="{!IF(!CEQ__c.Act__c ="Activity 1",true,false)}"/> 
</apex:pageBlockSection>

If so, I'm getting the error below:

Error: Incorrect parameter type for function 'not()'. Expected Boolean, received Text
karthikeyan perumalkarthikeyan perumal
Hello Elkid_24, 

you have used  " ! " 2 times in that condition not like that. 

<apex:outputField value="{!CEQ__c.Field1__c}" rendered="{ ! IF( ! CEQ__c.Act__c ="Activity1",true,false)}"/>-- (wrong

<apex:outputField value="{!CEQ__c.Field1__c}" rendered="{ ! IF(   CEQ__c.Act__c ="Activity1",true,false)}"/>--(Correct)

kinldy use the same as below. 
 
<b><!-- Activity 1  Show this section if lookup field name = Activity 1--></b>
<apex:pageBlockSection title="Activity 1">
<apex:outputField value="{!CEQ__c.Field1__c}" rendered="{!IF(CEQ__c.Act__c ="Activity 1",true,false)}"/> 
</apex:pageBlockSection>

use this above code and let me know.

Mark Best ANSWER if its works. 

Thanks
karthik