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
Ankit Khurana24Ankit Khurana24 

how to show dependent picklist on vf page

how to show dependent picklist on vf page also controlling picklist need to be shown as radio button.

There are 2 dependent picklist in standard account object name Select region and Select Countries.....i need to show them on vf page such that  Select region should be as radio button....Slect region has 3 values ASIA,EUROPE AND ALL...and 10 countries values in Select Countries.first five for Asia ,last five for EUROPE ..and all values for all option are made..as dependent picklist..

....i am also able to convert picklist to radio button ..but dependent functionality is not working with radio button..please help..below is the code..

apex page

<apex:page standardController="account" extensions="CountryClass">
<apex:form >

<apex:pageBlock title="Dependent Picklist" mode="edit">
<apex:pageBlockSection columns="2">
<apex:inputField value="{!account.Select_REGION__c}">
<apex:selectoptions value="{!types}"></apex:selectoptions>

</apex:inputField>
<apex:inputField value="{!account.Select_Countries__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

controller

public class CountryClass
{

public CountryClass(ApexPages.StandardController controller)
{

}

public List<SelectOption> getTypes()
{
Schema.sObjectType sobject_type = account.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_Region__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;
}

}

 

 

Ankit AroraAnkit Arora

If both picklist are dependent on object level then just by showing them using input field will work. Not sure why you want to make the first picklist as radio button? Any specific reason or you just want to force the user to select atleast 1 value in region picklist?

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Ankit Khurana24Ankit Khurana24

Hi Ankit,

 

You are right when both picklist are showm on vf page they work fine.but i have to make that pickllist as radio button..that actaullly is not working.please let me know solution.

Ankit AroraAnkit Arora

Yes, if you are displaying radio button instead of inputfield then it won't work. But that is my question to you. Why you want to use radio buttons instead of picklist? As in both user can select only 1 value.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Ankit Khurana24Ankit Khurana24

that is the required..atleast one value must be selected...so it  need radio button

Ankit AroraAnkit Arora

Ahh I see, so why don't you make that picklist as required on page by changing in page layout and then it will be required. You don't need radio in that case :-)

 

Let me know if it still doesn't work.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Ankit Khurana24Ankit Khurana24

That is client requirement..i have to bind radio button with picklist...I can't change there might be some buisness logic attached to it.

Ankit AroraAnkit Arora

I think you need to write a custom logic to create the dependency, and to make work more easy check if you can get the dependency using describe.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page