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
gs0551gs0551 

Hide dependent field when picklist value is none

Hi,

I created a VF page where, checkbox appears dependent on the value of the picklist. For Example

Picklist vlaues are: Meets Best Practices, Partially Meets Best Practices, Doesnot Meet Best Practices. For each Picklist value a checkbox appears. My Problem here is when the picklist value is "none" then all the checkbox appear. I want then to appear only when picklist value is selected and hide all checkbox when the picklist value is none.

Here is the code: 
<apex:pageBlockSection collapsible="false" columns="1" title="Instructional Material">
<apex:inputField value="{!Class__c.QC_Material_Observation__c}" required="false">
<apex:actionsupport event="onchange" rerender="null,best,partial,doesnot"/>
</apex:inputField>
<apex:outputPanel >

</apex:outputPanel>
<apex:outputPanel id="best" >
<apex:pageBlockSection rendered="{!Contains(Class__c.QC_Material_Observation__c,'Meets Best Practices')}" >
<apex:inputCheckbox value="{!Class__c.QC_IM_Fine__c}"/>
<apex:inputCheckbox value="{!Class__c.QC_IM_Fine_Multimedia__c}"/>
</apex:pageBlockSection> 
</apex:outputPanel>

<apex:outputPanel id="partial" >
<apex:pageBlockSection rendered="{!Contains(Class__c.QC_Material_Observation__c,'Partially Meets Best Practice')}" >
<apex:inputCheckbox value="{!Class__c.QC_IM_Fine_Multimedia__c}"/>
</apex:pageBlockSection> 
</apex:outputPanel>

<apex:outputPanel id="doesnot" >
<apex:pageBlockSection rendered="{!Contains(Class__c.QC_Material_Observation__c,'Does not Meet Best Practices')}" >
<apex:inputCheckbox value="{!Class__c.QC_Third_Party_Material__c}"/>
<apex:inputCheckbox value="{!Class__c.QC_No_Lectures__c}"/>
</apex:pageBlockSection> 
</apex:outputPanel>
</apex:outputPanel> 

<apex:inputTextarea value="{!Class__c.QC_Material_Comments__c}" required="false" rows="10" cols="50" />
<apex:inputField value="{!Class__c.QC_Material_Score__c}" required="false"/>
</apex:pageblocksection>

 

Best Answer chosen by Admin (Salesforce Developers) 
Gunners_23Gunners_23

Please add the condition to whether the picklist value is none in all pageblocksection and based on it render it

 

For ex :

 

<apex:pageBlockSection rendered="{!Class__c.QC_Material_Observation__c=='Meets Best Practices'  }" >

 

similarly add this condition for other pageblock section tags.

 

Let me know if it didn't work

All Answers

Gunners_23Gunners_23

Please add the condition to whether the picklist value is none in all pageblocksection and based on it render it

 

For ex :

 

<apex:pageBlockSection rendered="{!Class__c.QC_Material_Observation__c=='Meets Best Practices'  }" >

 

similarly add this condition for other pageblock section tags.

 

Let me know if it didn't work

This was selected as the best answer
sivaextsivaext

Hi 

 

try this

 

 Please remove this line in code.

 

<apex:actionsupport event="onchange" rerender="null,best,partial,doesnot"/>
gs0551gs0551

It worked when i slightly changed the condition. 

 

<apex:outputPanel id="best1" >
<apex:inputfield rendered="{!Class__c.QC_Material_Observation__c=='Meets Best Practices'}" >
<apex:inputCheckbox value="{!Class__c.QC_IM_Fine__c}"/>
<apex:inputCheckbox value="{!Class__c.QC_IM_Fine_Multimedia__c}"/>
</apex:inputfield>
</apex:outputPanel>

 

Now I dont see the checkboxes for "none" picklist !!! Yipee.. thanks a million

 

gs0551gs0551

That Line is important to rerender. But yes I removed "Null " from that line. Thanks anyways