+ Start a Discussion
balubalu 

Dependent picklist not working if the Controlling field is an output field in Visualforce page.

Hello,

I am creating a Visualforce page using new version 19.

I have two dependent picklist fields. When the controlling field is an inputfield the dependent picklist is filtered.

If I change the controlling field to an outputfield the dependent picklist shows all the values (it is not filtering).

The value of the controlling field is auto populated.

 

Is there a work around to maintain the dependency by keeping the controlling field as outputfield.

 

Dependency Works:

 

<apex:page standardController="opportunity" tabstyle="Opportunity" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Sample" columns="1">
                <apex:inputField value="{!opportunity.Segment__c}"/>
                <apex:inputField value="{!Opportunity.Department__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Dependency does,t Work:

 

<apex:page standardController="opportunity" tabstyle="Opportunity" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Sample" columns="1">
                <apex:outputfield value="{!opportunity.Segment__c}"/>
                <apex:inputField value="{!Opportunity.Department__c}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Thanks for you time.

 

AvromAvrom

That's correct. From the VisualForce developer's guide:

 

"To use this feature, define a field dependency between picklist, multi-picklist, radio button, or checkbox fields on any object. Then, place these fields on your page using the <apex:inputField> component." (emphasis mine)

 

The truth actually goes a bit further than that: Both fields must be rendered, non-read-only apex:inputField components in order for dependent picklists to function. If you need to filter a picklist but don't want the controlling field to be rendered, or editable, you should use an <apex:selectList> with <apex:selectOptions>.

 

Pradeep_NavatarPradeep_Navatar

In my opinion you can not use <apex:outfield>  for the dependent picklist.  See the sample code given below :

 

<apex:inputField value="{!account.industry}"/>
<apex:inputField value="{!account.subcategories__c}"/>