Required Dynamic Drop Downs

I have two questions about dynamic drop downs.

Question 1: How can I make the dynamic field be required?
Question 2: If I have a multi-level dynamic field. for example: Office type effects. Office Building Type effects Location. When you change Office Type, Office Building Type Updates but the filed Location displays all options until the Building Type is selected. How can we trigger the update to Location?

Hi, I’ve done this in the past and it wasn’t too complicated. I found a tutorial on how to do it adding some custom code, I can’t remember the exact resource right now but a quick google search throws some results:

I hope it helps!


I have done it without any special things:

  1. Make Dynamic Drop Down required (see also notes in the second image)
    Just go to Admin->Studio->the module in which you have the field->Fields
    Scroll down the list and click on your field
    Once you are in the edit form of the field you have to check the option Required (it is at the bottom of the form). See my example:

  1. List the correct options
    Are you sure you defined the field correctly?
    If it is correct you can try editing your dropdowns (studio->dropdown editor-> click your dropdowns) and you could insert a blank option like in this example:

Alternatively you can edit the file: include/language/en_us.lang.php and , as the first item of each of your dropdowns you could insert a blank option like in this example:

$GLOBALS['app_list_strings']['press_agency_media_type_list']=array (
  '' => '',
  'blog' => 'Blog',
  'books' => 'Books',
  'catalogue' => 'Catalogue',
  'directory' => 'Directory',
  'internet' => 'Internet',
  'magazine' => 'Magazine',
  'newspaper' => 'Newspaper',
  'press_agency' => 'Press Agency',
  'radio' => 'Radio',
  'supplement' => 'Supplement',
  'television' => 'Television',
  'writing_agency' => 'Writing Agency',
  'other' => 'Other',

Be very careful when editing this file.

Thank you for your example:

However, to trigger the second drop down the keys would be


The first word corresponds to the parent’s key value.

I gave youi just an example and I have used different dropdowns. Probably first levels.

In any case you should aim at something like this

The format I using here is: ‘Key’ - ‘Label’

Dropdown 1
‘’ - ‘’ <- note they are both blank!!!
‘d1a’ - ‘Label for d1a’ <- note there is no underscore: it is used to separate the different levels so it is better not to use it for other purposes
‘d1b’ - ‘Label for d1b’
‘d1c’ - ‘Label for d1b’

Dropdown 2
‘’ - ‘’ <- note they are both blank!!!
‘d1a_d2a’ - ‘Label for d2a’ <- note the key has two sub keys separated by an underscore
‘d1a_d2b’ - ‘Label for d2b’
'd1a_d2c - ‘Label for d2c’

‘d1b_d2d’ - ‘Label for d2d’
‘d1b_d2e’ - ‘Label for d2e’
'd1b_d2f - ‘Label for d2f’

‘d1c_d2g’ - ‘Label for d2d’
‘d1c_d2h’ - ‘Label for d2e’
'd1c_d2i - ‘Label for d2f’

Dropdown 3
‘’ - ‘’ <- note they are both blank!!!
‘d1a_d2a_d3a’ - ‘Label for d3a’ <- note the key has three sub keys separated by an underscore
‘d1a_d2a_d3b’ - ‘Label for d3b’
‘d1a_d2a_d3c’ - ‘Label for d3c’

‘d1a_d2b_d3d’ - ‘Label for d3d’
‘d1a_d2b_d3e’ - ‘Label for d3e’
‘d1a_d2b_d3f’ - ‘Label for d3f’

‘d1c_d2i_d3xx’ - ‘Label for d3xx’
‘d1c_d2i_d3xy’ - ‘Label for d3xy’
‘d1c_d2i_d3xz’ - ‘Label for d3xz’

I hope you undertsnd how to proceed.

Remember to mark the fields as required and don’t put, if prompted, a default value except the blank values.

The concept is the following:

  1. The field is required
  2. the first value in the list gets selected
  3. If you don’t pick any value the first value remains and, since it’s blank the save button will produce an error message and force you to choose a value

The “” => “” options do not appear for the second field.

First Field -> apartment

Second Field list

$app_list_strings['mylist']['apartment_'] = '';  //this appears
$app_list_strings['mylist'][''] = ''; // this does not appear
$app_list_strings['mylist']['apartment_selfcontainedroi'] = 'Self-Contained';
$app_list_strings['mylist']['apartment_summaryroi'] = 'Summary';
$app_list_strings['myhlist']['apartment_restricteduseroi'] = 'Restricted Use';
$app_list_strings['mylist']['apartment_nycrestrictedrent'] = 'NYC Restricted Rent

apartment_ is not blank thus the field does not get flagged as required

I don’t think you defined the dropdowns correctly.

The following is a working example:
(these are taken from the file custom/include/language/en_us.lang.php)

$GLOBALS['app_list_strings']['press_agency_continents_list']=array (
  '' => '',
  'Asia' => 'Asia',
  'Europe' => 'Europe',
  'Africa' => 'Africa',
  'Oceania' => 'Oceania',
  'NorthAmerica' => 'North America',
  'Antarctica' => 'Antarctica',
  'SouthAmerica' => 'South America',
  'U' => 'Unknown Continent',

$GLOBALS['app_list_strings']['press_agency_countries_list']=array (
  '' => '',
  'U_U' => 'Unknown Country and Continent',
  'Europe_U' => 'Unknown Europe',
  'Africa_U' => 'Unknown Africa',
  'Oceania_U' => 'Unknown Oceania',
  'NorthAmerica_U' => 'Unknown North America',
  'Antarctica_U' => 'Unknown Antarctica',
  'SouthAmerica_U' => 'Unknown South America',
  'Europe_ALA' => '&Aring;land Islands',
  'Asia_AFG' => 'Afghanistan',
  'Europe_ALB' => 'Albania',
  'Africa_DZA' => 'Algeria',
  'Oceania_ASM' => 'American Samoa',
  'Europe_AND' => 'Andorra',
  'Africa_AGO' => 'Angola',
  'NorthAmerica_AIA' => 'Anguilla',
  'Antarctica_ATA' => 'Antarctica',
  'NorthAmerica_ATG' => 'Antigua and Barbuda',
  'SouthAmerica_ARG' => 'Argentina',
  'Asia_ARM' => 'Armenia',
  'NorthAmerica_ABW' => 'Aruba',
  'Oceania_AUS' => 'Australia',
  'Europe_AUT' => 'Austria',
  'Asia_AZE' => 'Azerbaijan',
  'NorthAmerica_BHS' => 'Bahamas',
  'Asia_BHR' => 'Bahrain',
  'Asia_BGD' => 'Bangladesh',
  'NorthAmerica_BRB' => 'Barbados',
  'Europe_BLR' => 'Belarus',
  'Europe_BEL' => 'Belgium',
  'NorthAmerica_BLZ' => 'Belize',
  'Africa_BEN' => 'Benin',
  'NorthAmerica_BMU' => 'Bermuda',
  'Asia_BTN' => 'Bhutan',
  'SouthAmerica_BOL' => 'Bolivia',
  'Europe_BIH' => 'Bosnia and Herzegovina',
  'Africa_BWA' => 'Botswana',
  'Antarctica_BVT' => 'Bouvet Island',
  'SouthAmerica_BRA' => 'Brazil',
  'Asia_IOT' => 'British Indian Ocean Territory',
  'Asia_BRN' => 'Brunei Darussalam',
  'Europe_BGR' => 'Bulgaria',
  'Africa_BFA' => 'Burkina Faso',
  'Africa_BDI' => 'Burundi',
  'Asia_KHM' => 'Cambodia',
  'Africa_CMR' => 'Cameroon',
  'NorthAmerica_CAN' => 'Canada',
  'Africa_CPV' => 'Cape Verde',
  'NorthAmerica_CYM' => 'Cayman Islands',
  'Africa_CAF' => 'Central African Republic',
  'Africa_TCD' => 'Chad',
  'SouthAmerica_CHL' => 'Chile',
  'Asia_CHN' => 'China',
  'Asia_CXR' => 'Christmas Island',
  'Asia_CCK' => 'Cocos (Keeling) Islands',
  'SouthAmerica_COL' => 'Colombia',
  'Africa_COM' => 'Comoros',
  'Africa_COG' => 'Congo',
  'Africa_COD' => 'The Democratic Republic of The Congo',
  'Oceania_COK' => 'Cook Islands',
  'NorthAmerica_CRI' => 'Costa Rica',
  'Africa_CIV' => 'Cote D\'ivoire',
  'Europe_HRV' => 'Croatia',
  'NorthAmerica_CUB' => 'Cuba',
  'Asia_CYP' => 'Cyprus',
  'Europe_CZE' => 'Czech Republic',
  'Europe_DNK' => 'Denmark',
  'Africa_DJI' => 'Djibouti',
  'NorthAmerica_DMA' => 'Dominica',
  'NorthAmerica_DOM' => 'Dominican Republic',
  'SouthAmerica_ECU' => 'Ecuador',
  'Africa_EGY' => 'Egypt',
  'NorthAmerica_SLV' => 'El Salvador',
  'Africa_GNQ' => 'Equatorial Guinea',
  'Africa_ERI' => 'Eritrea',
  'Europe_EST' => 'Estonia',
  'Africa_ETH' => 'Ethiopia',
  'SouthAmerica_FLK' => 'Falkland Islands (Malvinas)',
  'Europe_FRO' => 'Faroe Islands',
  'Oceania_FJI' => 'Fiji',
  'Europe_FIN' => 'Finland',
  'Europe_FRA' => 'France',
  'SouthAmerica_GUF' => 'French Guiana',
  'Oceania_PYF' => 'French Polynesia',
  'Antarctica_ATF' => 'French Southern Territories',
  'Africa_GAB' => 'Gabon',
  'Africa_GMB' => 'Gambia',
  'Asia_GEO' => 'Georgia',
  'Europe_DEU' => 'Germany',
  'Africa_GHA' => 'Ghana',
  'Europe_GIB' => 'Gibraltar',
  'Europe_GRC' => 'Greece',
  'NorthAmerica_GRL' => 'Greenland',
  'NorthAmerica_GRD' => 'Grenada',
  'NorthAmerica_GLP' => 'Guadeloupe',
  'Oceania_GUM' => 'Guam',
  'NorthAmerica_GTM' => 'Guatemala',
  'Europe_GGY' => 'Guernsey',
  'Africa_GIN' => 'Guinea',
  'Africa_GNB' => 'Guinea-bissau',
  'SouthAmerica_GUY' => 'Guyana',
  'NorthAmerica_HTI' => 'Haiti',
  'Antarctica_HMD' => 'Heard Island and Mcdonald Islands',
  'Europe_VAT' => 'Holy See (Vatican City State)',
  'NorthAmerica_HND' => 'Honduras',
  'Asia_HKG' => 'Hong Kong',
  'Europe_HUN' => 'Hungary',
  'Europe_ISL' => 'Iceland',
  'Asia_IND' => 'India',
  'Asia_IDN' => 'Indonesia',
  'Asia_IRN' => 'Iran',
  'Asia_IRQ' => 'Iraq',
  'Europe_IRL' => 'Ireland',
  'Europe_IMN' => 'Isle of Man',
  'Asia_ISR' => 'Israel',
  'Europe_ITA' => 'Italy',
  'NorthAmerica_JAM' => 'Jamaica',
  'Asia_JPN' => 'Japan',
  'Europe_JEY' => 'Jersey',
  'Asia_JOR' => 'Jordan',
  'Asia_KAZ' => 'Kazakhstan',
  'Africa_KEN' => 'Kenya',
  'Oceania_KIR' => 'Kiribati',
  'Asia_PRK' => 'Democratic People\'s Republic of Korea',
  'Asia_KOR' => 'Republic of Korea',
  'Asia_KWT' => 'Kuwait',
  'Asia_KGZ' => 'Kyrgyzstan',
  'Asia_LAO' => 'Lao People\'s Democratic Republic',
  'Europe_LVA' => 'Latvia',
  'Asia_LBN' => 'Lebanon',
  'Africa_LSO' => 'Lesotho',
  'Africa_LBR' => 'Liberia',
  'Africa_LBY' => 'Libya',
  'Europe_LIE' => 'Liechtenstein',
  'Europe_LTU' => 'Lithuania',
  'Europe_LUX' => 'Luxembourg',
  'Asia_MAC' => 'Macao',
  'Europe_MKD' => 'Macedonia',
  'Africa_MDG' => 'Madagascar',
  'Africa_MWI' => 'Malawi',
  'Asia_MYS' => 'Malaysia',
  'Asia_MDV' => 'Maldives',
  'Africa_MLI' => 'Mali',
  'Europe_MLT' => 'Malta',
  'Oceania_MHL' => 'Marshall Islands',
  'NorthAmerica_MTQ' => 'Martinique',
  'Africa_MRT' => 'Mauritania',
  'Africa_MUS' => 'Mauritius',
  'Africa_MYT' => 'Mayotte',
  'NorthAmerica_MEX' => 'Mexico',
  'Oceania_FSM' => 'Micronesia',
  'Europe_MDA' => 'Moldova',
  'Europe_MCO' => 'Monaco',
  'Asia_MNG' => 'Mongolia',
  'Europe_MNE' => 'Montenegro',
  'NorthAmerica_MSR' => 'Montserrat',
  'Africa_MAR' => 'Morocco',
  'Africa_MOZ' => 'Mozambique',
  'Asia_MMR' => 'Myanmar',
  'Africa_NAM' => 'Namibia',
  'Oceania_NRU' => 'Nauru',
  'Asia_NPL' => 'Nepal',
  'Europe_NLD' => 'Netherlands',
  'NorthAmerica_ANT' => 'Netherlands Antilles',
  'Oceania_NCL' => 'New Caledonia',
  'Oceania_NZL' => 'New Zealand',
  'NorthAmerica_NIC' => 'Nicaragua',
  'Africa_NER' => 'Niger',
  'Africa_NGA' => 'Nigeria',
  'Oceania_NIU' => 'Niue',
  'Oceania_NFK' => 'Norfolk Island',
  'Oceania_MNP' => 'Northern Mariana Islands',
  'Europe_NOR' => 'Norway',
  'Asia_OMN' => 'Oman',
  'Asia_PAK' => 'Pakistan',
  'Oceania_PLW' => 'Palau',
  'Asia_PSE' => 'Palestinia',
  'NorthAmerica_PAN' => 'Panama',
  'Oceania_PNG' => 'Papua New Guinea',
  'SouthAmerica_PRY' => 'Paraguay',
  'SouthAmerica_PER' => 'Peru',
  'Asia_PHL' => 'Philippines',
  'Oceania_PCN' => 'Pitcairn',
  'Europe_POL' => 'Poland',
  'Europe_PRT' => 'Portugal',
  'NorthAmerica_PRI' => 'Puerto Rico',
  'Asia_QAT' => 'Qatar',
  'Africa_REU' => 'Reunion',
  'Europe_ROM' => 'Romania',
  'Europe_RUS' => 'Russian Federation',
  'Africa_RWA' => 'Rwanda',
  'Africa_SHN' => 'Saint Helena',
  'NorthAmerica_KNA' => 'Saint Kitts and Nevis',
  'NorthAmerica_LCA' => 'Saint Lucia',
  'NorthAmerica_SPM' => 'Saint Pierre and Miquelon',
  'NorthAmerica_VCT' => 'Saint Vincent and The Grenadines',
  'Oceania_WSM' => 'Samoa',
  'Europe_SMR' => 'San Marino',
  'Africa_STP' => 'Sao Tome and Principe',
  'Asia_SAU' => 'Saudi Arabia',
  'Africa_SEN' => 'Senegal',
  'Europe_SRB' => 'Serbia',
  'Africa_SYC' => 'Seychelles',
  'Africa_SLE' => 'Sierra Leone',
  'Asia_SGP' => 'Singapore',
  'Europe_SVK' => 'Slovakia',
  'Europe_SVN' => 'Slovenia',
  'Oceania_SLB' => 'Solomon Islands',
  'Africa_SOM' => 'Somalia',
  'Africa_ZAF' => 'South Africa',
  'Africa_SSD' => 'South Sudan',
  'Antarctica_SGS' => 'South Georgia and The South Sandwich Islands',
  'Europe_ESP' => 'Spain',
  'Asia_LKA' => 'Sri Lanka',
  'Africa_SDN' => 'Sudan',
  'SouthAmerica_SUR' => 'Suriname',
  'Europe_SJM' => 'Svalbard and Jan Mayen',
  'Africa_SWZ' => 'Swaziland',
  'Europe_SWE' => 'Sweden',
  'Europe_CHE' => 'Switzerland',
  'Asia_SYR' => 'Syrian Arab Republic',
  'Asia_TWN' => 'Taiwan, Province of China',
  'Asia_TJK' => 'Tajikistan',
  'Africa_TZA' => 'Tanzania, United Republic of',
  'Asia_THA' => 'Thailand',
  'Asia_TLS' => 'Timor-leste',
  'Africa_TGO' => 'Togo',
  'Oceania_TKL' => 'Tokelau',
  'Oceania_TON' => 'Tonga',
  'NorthAmerica_TTO' => 'Trinidad and Tobago',
  'Africa_TUN' => 'Tunisia',
  'Asia_TUR' => 'Turkey',
  'Asia_TKM' => 'Turkmenistan',
  'NorthAmerica_TCA' => 'Turks and Caicos Islands',
  'Oceania_TUV' => 'Tuvalu',
  'Africa_UGA' => 'Uganda',
  'Europe_UKR' => 'Ukraine',
  'Asia_ARE' => 'United Arab Emirates',
  'Europe_GBR' => 'United Kingdom',
  'NorthAmerica_USA' => 'United States',
  'Oceania_UMI' => 'United States Minor Outlying Islands',
  'SouthAmerica_URY' => 'Uruguay',
  'Asia_UZB' => 'Uzbekistan',
  'Oceania_VUT' => 'Vanuatu',
  'SouthAmerica_VEN' => 'Venezuela',
  'Asia_VNM' => 'Viet Nam',
  'NorthAmerica_VGB' => 'Virgin Islands, British',
  'NorthAmerica_VIR' => 'Virgin Islands, U.S.',
  'Oceania_WLF' => 'Wallis and Futuna',
  'Africa_ESH' => 'Western Sahara',
  'Asia_YEM' => 'Yemen',
  'Africa_ZMB' => 'Zambia',
  'Africa_ZWE' => 'Zimbabwe',
  'Asia_U' => 'Unknown Asia',
  'Europe_U' => 'Unknown Europe',
  'Africa_U' => 'Unknown Africa',
  'Oceania_U' => 'Unknown Oceania',
  'NorthAmerica_U' => 'Unknown North America',
  'Antarctica_U' => 'Unknown Antarctica',
  'SouthAmerica_U' => 'Unknown South America',

Additionally you have to go in Studio and define the parent field as a normal dropdown:
see image

Once you have defined the parent field you define the child field as a DynamicDropdown and in the Parent Dropdown form field you enter the name of the parent field followed by_c (note that this is the name of the parent dropdown field in the way you have defined it in Studio and not the name of the dropdown, which can be found in custom/include/language/en_us.lang.php
see image:

Once done I recommend that you edit the database table called fields_meta_data and set to NULL the values of the two fields (Parent DropDown and child DynamicDropDown)
see image:

If you have other grand children or grand grand children you proceed in the same way.

I have it setup exactly as you have defined.

Let me be more clear.

When the user select Asia
Your drop down will display all of the Asia_ options such as

‘Asia_AFG’ => ‘Afghanistan’,
‘Asia_ARM’ => ‘Armenia’,

What I need is for the first element to be blank when the person chooses Asia
So the drop down should look like

  • Blank -

If the user were to attempt to save at this point, the selected option is blank so the user must select an option. Blank should not be a valid option.

In your setup… Afghanistan will be selected and the user may incorrectly accept the default selection which will not be correct.

First of all, thanks to this thread I noticed that I had not entered the empty value for Asia!
In my situation I am setting an Unknown Country value for each continent at the top of the countries list.
This makes it easy to search them.

As you correctly state if we use Europe_ as key then the value is not considered as empty and the message is not shown.

I have tried a logic hook and, while I am able to reset the value to null in before_save, I don’t know how to return the focus back to the form.

I have read some posts googling around that it is better to write soe custom javascript validation of the form in order to avoid saving the record.

I will investigate it as it may become useful.

In the mean time you could assign an Unknown value and run a workflow which, in case an unknown value is detected it will send an email to the user reminding him to correct the value (very annoying but not the best solution).

[color=#0000ff]Thank you for your reply. I am not able to make the Dynamic Drop Downs Required.
I have added the field as a required field. The field shows up okay and I can select the parent entity, but it is not required, which it should be. Also, the required sign (*) does not appear against the field. Any help will be highly appreciated. :slight_smile: [/color]

@amariussi how to add this using custom code in editviewdefs.php?. I tried using this code below, but no luck all list will display if I have this custom code.

          array (
            'name' => 'custom_province_c',
            'label' => 'LBL_PROVINCE',
            'customCode' => '{html_options name="custom_province_c" id="custom_province_c" options=$fields.custom_province_c.options selected=$fields.custom_province_c.value}&nbsp;<span id="error_province_msg"></span>',
          1 => 
          array (
            'name' => 'custom_city_c',
            'label' => 'LBL_CITY',
            'customCode' => '{html_options name="custom_city_c" id="custom_city_c" options=$fields.custom_city_c.options selected=$fields.custom_city_c.value}&nbsp;<span id="error_city_msg"></span>',
        2 => 
        array (
          0 => 
          array (
            'name' => 'custom_barangay_c',
            'label' => 'LBL_BARANGAY',
            'customCode' => '{html_options name="custom_barangay_c" id="custom_barangay_c" options=$fields.custom_barangay_c.options selected=$fields.custom_barangay_c.value}&nbsp;<span id="error_barangay_msg"></span>',

Can you be more specific on what you are trying to achieve and what have you done so far?

I am not sure I get your intentions.

@amariussi , its ok anyway I was able to implement what I wanted to.