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
MRosiMRosi 

Prefiltered dependent picklists

Hello,

 

I have a set of three dependent picklists in my Item__c object: Item__c.Type__c, Item__c.Subtype__c and Item__c.Subsubtype__c. The latter two picklists have many entries each.

 

How do I display just the latter two picklists prefiltered based on a hidden input tag that sets Item__c.Type__c?

 

Here is my code and the behavior I am seeing. It seems to be some kind of bug, or maybe I am just obtuse ;)

 

In VF:

<apex:page showHeader="false" standardController="Item__c" extensions="factoryTxnProductReg">

 

1) In following code, Subtype does not get narrowed down. However, when subtype is selected, subsubtype does narrow down.

<input type="hidden" name="{!Item__c.Type__c}" value="Raw Materials"/>

<apex:inputField value="{!Item__c.Subtype__c}"/>

<apex:inputField value="{!Item__c.Subsubtype__c}"/>

(Here, even if in apex constructor we have item.Type__c = myitemtype but still the subtype picklist does not narrowed down. maybe I should be using getter..?)

 

2) When the following code is used, selecting a Subtype does not narrow down the Subsubtype field.

<input type="hidden" name="{!Item__c.Type__c}" value="Raw Materials"/>

<apex:selectList id="optlist" value="{!Item__c.Subtype__c}" multiselect="false">

  <apex:selectOption itemValue="Containers" itemLabel="Containers"/>

  <apex:selectOption itemValue="Other" itemLabel="Other"/>

</apex:selectList>

<apex:inputField value="{!Item__c.Subsubtype__c}"/>

 

Additional information regarding case 1 above:

 

Although I have seen invisible differences in encoding (using UTF-8 to show Japanese, I have translated to post here) I have double-checked by copy-pasting from the picklist value edit dialog box into Eclipse so this is not an issue.

 

Additional information regarding case 2 above:

 

Type <apex:inputField value="{!Item__c.Type__c}" id="itemtype" onchange="itemtype.value='Raw Materials'" rendered="true"/>{!Item__c.Type__c}

Subtype <apex:inputField value="{!Item__c.Subtype__c}"/>

 

The above code works as follows:

- Type picklist is displayed, showing all values of the picklist (which is not what I want)

- Type gets set to Raw Materials, and Subtype picklist gets narrowed down correctly.

- Even if a different value such as "Waste" is selected for Type, the Subtype picklist remains narrowed down as if Type still equals Raw Materials. 

- However, the Type picklist displays "Waste". (Which is confusing since the UI lies, displaying the a different value from that to which the Type variable was set.)

- I was unable to obtain the desired action with other javascript tags than onchange.

- Should I be making an Action?

- If rendered is changed to "False", the Subtype picklist does not get narrowed down anymore.

I think this is a bug… do I get a t-shirt?

 

Thanks for your help,

 

Matt

Best Answer chosen by Admin (Salesforce Developers) 
LakshmanLakshman

Hi Matt,

 

I have a workaround for your problem. Try doing following:

 

<apex:inputField value="{!Item__c.Type__c}" style="display:none"/>

<apex:inputField value="{!Item__c.Subtype__c}"/>

<apex:inputField value="{!Item__c.Subsubtype__c}"/>

 

Now set the default value of picklist Type__c to "Raw Materials" or whatever you want. It will work as you expect.

Let me know if it works.

 

Regards,

Lakshman



All Answers

LakshmanLakshman

Hi Matt,

 

I have a workaround for your problem. Try doing following:

 

<apex:inputField value="{!Item__c.Type__c}" style="display:none"/>

<apex:inputField value="{!Item__c.Subtype__c}"/>

<apex:inputField value="{!Item__c.Subsubtype__c}"/>

 

Now set the default value of picklist Type__c to "Raw Materials" or whatever you want. It will work as you expect.

Let me know if it works.

 

Regards,

Lakshman



This was selected as the best answer
MRosiMRosi

Dear Lakshman,

 

Thank you!!! You are way better than Premier Support who are taking days!!! ;)

 

I am flabbergasted. I bow before your CSS superpowers!

 

This has to make it into the manuals...

 

Warm regards,

 

Matt

MRosiMRosi

p.s. I told them you deserve to be paid a salary!

Matt

LakshmanLakshman

I am so glad that I could help you!

 

Regards,

Lakshman