You need to sign in to do that
Don't have an account?
krishna casukhela 7
How to fetch values into dependent picklist
I am having a piece of code which fetches countryname along with its code from custom setting
and populates the country name into the visual force page.
In custom setting, type=LIST , anme is Countries__c and it has a field called CountryCode__c.
if the user selects Australia from vf page and click SAVE button then 'CA' is stored in the backend and so on.
The values in custom settings are not very huge.
Now i need to have another picklsit in vf page , which will display the state name based on the country selected.
I want to store the states names also in custom settings(state names are not many just a few).
Here is what I have achieved so far.
Please let me know how to capture value of first picklsit and based on that get the states for that country.
also how to design the custom setting so as to include the states and how to use changes in vf page.
I request the forum members to help me out urgently.
Thanks
krishna
and populates the country name into the visual force page.
In custom setting, type=LIST , anme is Countries__c and it has a field called CountryCode__c.
if the user selects Australia from vf page and click SAVE button then 'CA' is stored in the backend and so on.
The values in custom settings are not very huge.
Now i need to have another picklsit in vf page , which will display the state name based on the country selected.
I want to store the states names also in custom settings(state names are not many just a few).
Here is what I have achieved so far.
public List<SelectOption> CountryCodeList=new List<SelectOption>(); public String selectedCountryCode {get; set;} public List<SelectOption> getCountryCodes() { if(countryCodeList.isEmpty()) { countryCodeList=new List<SelectOption>(); List<Countries__c> allCountries = new List<Countries__c>(); allCountries = [SELECT Name,CountryCode__c FROM Countries__c]; allCountries.sort(); List<Countries__c> cList=new List<Countries__c>([select CountryCode__c from Countries__c where CountryCode__c=:selectedCountryCode]); if (cList.size() > 0) { for(Countries__c country : allCountries ) { countryCodeList.add( new SelectOption( country.CountryCode__c, country.Name ) ); } } else { countryCodeList.add(new SelectOption('--Select--', '--Select--')); } } return countryCodeList; } <apex:selectOption itemValue=" " itemLabel="--Select--"></apex:selectOption> <apex:selectOptions value="{!countryCodes}"></apex:selectOptions> </apex:selectList>
Please let me know how to capture value of first picklsit and based on that get the states for that country.
also how to design the custom setting so as to include the states and how to use changes in vf page.
I request the forum members to help me out urgently.
Thanks
krishna
there is your vf page and controller codes; i have tested myself its working fine now.
Hope it helps!
good day !
All Answers
Hi Krishna,
You are already
this will capture the value from your Country picklist in "selectedCountryCode" string variable and then populate the new state picklist of state
Make the custom settings with the country code and state field so that they remain mapped
hope this help
good day
Why you want to maintain picklist in custom setting .I think better you can create two picklist and add controlling and dependency then use in page .
Else you need to do more coding to achieve this .
If you want to add picklist in cutom setting it will be a developer dependent always .
YOu can do one thing you can craete object country and state craete record and have relationship and use in code .
Let me know if it helps !!
Thanks
Manoj
For country=Canada, the states data is Alberta":"Alberta
I created a new custom setting called States__C and under this two fields , CountryCodes__c and StatesCode__c.
CountryCodes__c=CA
StatesCode__c=Alberta
Here is the code what I have done.
But the states are not populated when I select Country as Canada.
Please help me to fix this issue urgent.
Thanks
krishna
there is your vf page and controller codes; i have tested myself its working fine now.
Hope it helps!
good day !
I went thru ur code , I have a doubt.
State__c, and Country_Region__c are two fields in the custom object.
so how do I load values into these two fields when the page loads and also how to save values in object fields.
In country_Region__c the countrycode is stored.
thanks
krishna
hi krishna,
just add a command button on ur vfpage calling a controller function int it and in this fuction map the string variables that have value of state and country into the fields of custom object , and simply insert it , this will store the record.
or
initialize a custom object into the constructor of your controller and and directly call the value into the fields of this object and with the click of save button insert the record which will store it.
youre welcome,
mohd anas
I have put up the full code below.
The code is able to populate the countries but its not showing the states for the country.
Also please let me know how to ferch the values and save the values. Please help me to fix this.
Thanks
krishna