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
Jina ChetiaJina Chetia 

How to make dependent picklist work in VisualForce page?

Hi,

I have a Contract Terms Custom Object which has a dependent picklist named 'Territory' depending on 'Region' picklist. I have used these two picklist in my page using the inputField tag but I am not getting the behaviour of the depending picklist. As soon as I change the Region value, the Territory picklist values should change depending on the value selected but it does not happen.

Here is the piece of code
Code:
        <apex:pageBlock title="Section 2" rendered="{!showSecondSection}">
            <p>To what geography does this rate apply— </p>
             Region: <span style="padding:10px;"/>
             <apex:inputField value="{!contractTerms.REGION__c}"></apex:inputField>
             <p> Territory: <span style="padding:10px;"/>
             <apex:inputField id="territory" value="{!contractTerms.TERRITORY__c}"/></p>
             <p><span style="padding:10px;"/><apex:commandButton action="{!showSection3}" 
value="Continue" styleClass="btn"></apex:commandButton></p><br/> </apex:pageBlock>

 
Can anyone please help me resolve this issue?

Thanks,
Jina
ESES
Dependent picklists are not yet supported by inputfield out of the box. Hopefully they will be in one of the future releases.
Until then, if you want the dependency logic I think you'll have to build it yourself by using events (onBlur etc.) on inputfield in tandom with components like apex : actionSupport
AkiTAkiT
Is there any news on the dependent picklists? Are these going to be included in some future release?
KunlunKunlun
I have same problem, did you solve it?

I create 2 custom picklist field (A and B), B's value depends on A.

I wrot ajax and apex to set B's value when A changes. In sf I set B as {1,2,3} when A is 1. set B {2,3,4} when A is 2.

But I can not find the apex api to select dependency relation between A and B. I want to write code like below.
Select values from B where B.dependencyvalue = A.value.

do you know how to select the dependency relation between A and B?
KunlunKunlun

do you know how to select the dependency relation between A and B with Apex code?

my post it as below:
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=7138

angusgrantangusgrant
Surely there is a database table which stores the relationship between the picklist fields? Which can then be used in the apex to recreate this relationship. Does anyone know about this?
CTU007CTU007
Please, anyone has a solution?
paul-lmipaul-lmi

most of us are not looking for a javascript solution, but rather an Apex solution, run on platform, and completely compliant with on platform dependencies.

 

is there a way to access this information in Apex or not?

paul-lmipaul-lmi

furthermore, what is the point of the isDependentPicklist() method of Field Describe Result if you really can't do anything but confim, yes, this is a dependent picklist.

 

The solution here is to extend getPicklistValues() to accept a param, which is the selected value of the controlling field.  Are you listening Salesforce?

Sam.arjSam.arj

I was able to successfully implement Richard's solution, however when i hit save I receive a validation error message "Value is not valid"

 

I get this error on the dependentField! 

 

Any idea why?

VarunCVarunC

Sam.arj wrote:

I was able to successfully implement Richard's solution, however when i hit save I receive a validation error message "Value is not valid"

 

I get this error on the dependentField! 

 

Any idea why?


Sam, were you able to Resolve your error? I'm facing the same error.

narsavagepnarsavagep

OMG... you have to be kidding me... :( 

This is horribly frustrating. 

babbottbabbott

I got Richard's code to work properly (after fighting the "Value is not valid" validation errors).  The dependent pick lists must be populated from a VisualForce controller first.  See my solution here:

 

http://brandticeincoderland.blogspot.com/2010/01/fun-with-dependent-picklists-in.html

 

As a side note, please vote up this idea on idea exchange, so we don't have to implement silly workarounds:

 

http://sites.force.com/ideaexchange/ideaView?c=09a30000000D9xt&id=08730000000BrogAAC&returnUrl=%2Fapex%2FideaList%3Fc%3D09a30000000D9xt%26category%3DApex%2B%2526%2BVisualforce%250D 

Message Edited by babbott on 02-05-2010 05:58 PM

Message Edited by babbott on 02-05-2010 06:00 PM
ConejoConejo

Have you guys looked at this article:

 

 

http://wiki.developerforce.com/index.php/Extended_Functionality_of_Visualforce_-_Part_1

 

 

It looks pretty straightforward, a VF controller and an <actionSupport> tag.

 

Rich C.

babbottbabbott
Yes, the "dependent picklists - plus" solution would work, however, if you already have SF objects setup a certain way with dependencies, you would have to make a lot of changes to achieve this goal (i.e. creating new objects with dependencies between them, etc...).
atlantisatlantis

Hi Babbott,

 

I have read ur blog and followed ur steps. but it doesnt work.

 

I am not sure what the last parameter -- initialValues should be for function DependentPicklistHelper().

 

Could you give me an example?

 

Can it be set to ''?

 

Many thanks,

Thomas

 

fgwarb_devfgwarb_dev

In case anyone else stumbles across this thread, pretty sure VF now supports this:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_dependent_picklists.htm

Kirill_YunussovKirill_Yunussov

It is still not working properly.   If the value of the controlling field is changed in the controller, the dependent picklist is not trimmed down to specific values, but is displaying all of the values available.  

 

This is the case when the VF page is only displaying the dependent picklist, and is not displaying the controlling field.   If both fields are displayed on the page, then the dependency is working correctly.

 

AkiTAkiT

That is true, both controlling and dependent fields need to be in page then it works ok.

Workaround to have only the dependent field shown is to modify the page DOM with own javascript.