+ Start a Discussion
ChubbyChubby 

Field dependency in VF page

Hi All,

I have two picklist fields in vf page, i want to retain field dependency between the two in my page. I am using standard controller and no pageblock component used. Any ideas?

Thanks.
Best Answer chosen by Chubby
sukanya banekarsukanya banekar
Hi,
You can create directly 2 dependent picklist for an object and directly use them in vf page. Or if you are using custom picklist <apex:selectOption> then onselection of the field you need to render another picklist field. 

let me know if this helps.
 

All Answers

David HalesDavid Hales
Hi Chubby,

Please go through this. 
Link: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_dependent_picklists.htm

Please mark this as best answer if it solves your problem.

Best Regards 
David Hales(1058)
sukanya banekarsukanya banekar
Hi,
You can create directly 2 dependent picklist for an object and directly use them in vf page. Or if you are using custom picklist <apex:selectOption> then onselection of the field you need to render another picklist field. 

let me know if this helps.
 
This was selected as the best answer
Mustafa JhabuawalaMustafa Jhabuawala
If you are using standard controller that doesn't mean that the dependent picklist feature will come along with that.

To retain the field dependency in visualforce page, you need to write the logic in your VF page itself. For ex - on change of A picklist you have to change the values of B picklist using render events (as Sukanya suggested).
ChubbyChubby
Thanks evryone for your suggestions. 
@Mustafa, Using standard controller the dependent picklist feature is coming along with that.
ChubbyChubby
Hi Sukanya,

I am trying to develop custom picklists with dependency but the picklist values are not populating in VF page. i am not understanding what's going wrong. Below is my code can someone pls help.


VF PAGE:

<apex:page standardController="Account" extensions="Dependency_ctrl">
  <apex:form >
  <apex:pageBlock >
  <apex:pageBlockSection >
  <apex:pageblockSectionItem >
  <apex:outputLabel >Country</apex:outputLabel>
  <apex:selectList value="{!selectedCountry}" multiselect="false" size="1" required="true" label="type">
  <apex:selectOptions value="{!getcountry}"/>
  <apex:actionSupport event="onchange" reRender="City"/>
  </apex:selectList>
  </apex:pageblockSectionItem>
  <apex:pageblockSectionItem >
  <apex:outputlabel >City:</apex:outputlabel>
  <apex:selectList value="{!City}" id="City">
  <apex:selectOptions value="{!getCity}"/>
  </apex:selectList>
    </apex:pageblockSectionItem>
  </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>


Controller:
public with sharing class Dependency_ctrl {
    public Account acct;
    public string getCountry{get;set;}
    public string getCity{get;set;}
    public string selectedCountry{get;set;}
    public string City{get;set;}
    public Dependency_ctrl(ApexPages.StandardController controller) {
        
    }
   public List<SelectOption> getCountry(){
   List<SelectOption> options = new List<SelectOption>();

options.add( new SelectOption('None','--None--'));
options.add(new SelectOption('India','India'));
options.add( new SelectOption('USA','USA'));
options.add( new SelectOption('Australia','Australia'));
return options;

   
}

Thank You.