+ Start a Discussion
hkp716hkp716 

Picklist for VisualForce

Hi Everyone,

 

I have a picklist issue i can't get to work.  My 3rd pick list is dependent on my 2nd picklist and it works fine, but my 2nd picklist is not dependent on my 1st.  Is there a way set up a query in my controller or vforce page where values in my 2nd picklist only populate when when a certain value in my 1st pick list is selected? (Without using field dependancies in my object)

 

Some brands only have 1 or 2 product lines but instead all the product line show up in the picklist.

 

Thank again for your help,

-Hersh

 

My Controller:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

public class brands
{
public brands(ApexPages.StandardController controller)
{

}
public List<SelectOption> getTypes()
{
Schema.sObjectType sobject_type = product2.getSObjectType();
Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe();
Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap();

List<Schema.PicklistEntry> pick_list_values = field_map.get('Select_Brand__c').getDescribe().getPickListValues();
List<selectOption> options = new List<selectOption>();
for (Schema.PicklistEntry a : pick_list_values)
{
options.add(new selectOption(a.getLabel(), a.getValue()));
}
return options;
}

}

 

 

 <apex:page standardController="product2" extensions="brands">

<apex:form >

<apex:pageBlock title="Floor Planning" mode="edit">

<apex:pageBlockSection columns="1">

<apex:inputField value="{!product2.Brand__c}">

<apex:inputField value="{!product2.Product_Line__c}" />

<apex:inputField value="{!product2.Sub_Product_Line__c}" />

</apex:inputField>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

kamlesh_chauhankamlesh_chauhan

Hi,

 

There is a way to rerender 2nd dropdown list with the use of ActionSupport and fill 2nd picklist dynamically. However as per your current code, the easiest way to use javascript. Hope below URL might be helpful to you.

 

http://stackoverflow.com/questions/8368926/drop-down-options-to-hide-using-javascript

 

Regards,

Kamlesh Chauhan, (Founder & CTO)

LogicRain Technologies, (Salesforce and Force.com Development Division)

Cellular: +91-(997) 476-6800 Office: (732) 676-6400 Skype:kamlesh.logicrain

kamlesh@logicrain.com || http://www.logicrain.com || LinkedIn

 

Answers/Suggestions are my own.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.