How to create State dropdown dependent on the Country Selected

I have two dropdowns.

Country and State/Province.

I need to populate the State/Province dropdown based on the option selected in the Country field.

How can I achieve this? Any little assistance would help

I followed this link How to create an Associated Dropdown - #4 by amariussi , but I don’t want to create all states dropdowns myself. That will take a lot of time. I think there must be quicker way to do this which I am missing here.

Thanks for help.

1 Like

Did it myself. I downloaded the data from here.

I wrote this python script on it made all states data dependent on another list of countries made with Country code.

Province/State is dynamic dropdown here.

Country list look likes this

    $app_list_strings['countries_dom']=array(
        '' => '',
        'AF' => 'Afghanistan',
        'AL' => 'Albania',
        'DZ' => 'Algeria',
        ....
       ....
           'YE' => 'Yemen',
        'SA' => 'Saudi Arabia',
        'RE' => 'Russia',
    );

Python script for making states list is something like this

    for x in sorted_countries:
        country_name = x[0]
        country_code = x[1]
        states_str = x[5]
        states_list = states_str.split("|")
        for state in states_list:
            state = state.replace("'", "")
            output += "'" + country_code + "_" + state + "'" + " " + "=>" + " " + "'" + state + "'" + ","

Now list of states look like this

            $GLOBALS['app_list_strings']['province_country_dom']=array (
                '' => '',
                'AF_Badakhshan' => 'Badakhshan',
                'AF_Badghis' => 'Badghis','
                AF_Baghlan' => 'Baghlan',
                ....
                ....
               'ZW_Matabeleland South' => 'Matabeleland South',
                'ZW_Midlands' => 'Midlands',
            );

I hope you understand what I did here. I hope this helps some one. :grin:

2 Likes

One more thing worth to mention is that when you have all your data, you can just insert values manually into the language file:
custom/include/language/en_us.lang.php

That way you don’t need to insert values one by one on SuiteCRM.

1 Like