I have two dependent drop-down lists for the country and one for the state. I use this concept several times in a multi-stage web form. When the form loads, the list of countries is in order. When choosing a specific country, the list of conditions is also in order. Now the question arises: If there is some required field in the same part of the web form and the user does not fill it out, the form is updated and loses the entire list of states. In addition, when you move to the next step (multi-stage web form) and return to the same page, the value is lost. However, throughout the process, the value of the country selection list is retained. Selection options generated with ajax are not saved. Thanks in advance. Below is the code.
$form['submitted']['employment_history']['employer_1']['address_of_employer']['country']['#ajax'] = array( 'callback' => 'my_custom_ajax_callback_for_employer_one', 'wrapper' => 'edit-submitted-employment-history-employer-1-address-of-employer-state', 'method' => 'replace', ); function my_custom_ajax_callback_for_employer_one($from, $form_state) { $selected_country = $form_state['values']['submitted']['employment_history']['employer_1']['address_of_employer']['country']; $states = location_get_provinces($selected_country); $form['submitted']['employment_history']['employer_1']['address_of_employer']['state']= array( '#type' => 'select', '#options' => $states, '#attributes' => array('id' => 'edit-submitted-employment-history-employer-1-address-of-employer-state'), ); $form['rebuild'] = TRUE; return $form['submitted']['employment_history']['employer_1']['address_of_employer']['state']; }
source share