0

I get the following erros on selecting the selectbox. Here onchang of this field will populate another checkbox with city details id zipcode using ajax callback.

 $zipcode_options = get_all_zipcodes_ascending();

  // Populate Ort on auktion clone. 
  $selected = isset($auktion->zip_code) ? $auktion->zip_code : NULL;
  $selected = isset($form_state['values']['zip_code']) ? $form_state['values']['zip_code'] : $selected;
  $ort_options = _ajax_city_dropdown_options($selected);

  $form['zip_code'] = [
    '#type' => 'select',
    '#title' => t('PLZ'),
    '#options' => $zipcode_options,
    '#default_value' => isset($auktion->zip_code) ? $auktion->zip_code : "",
    '#select2' => ['width' => '100%', 'placeholder' => t('Enter a zipcode'), 'allowClear' => TRUE],
    '#empty_option' => '',
    '#validated' => TRUE,
    '#required' => TRUE,
    '#ajax' => array(
      'event' => 'change',
      'callback' => 'ajax_example_dependent_dropdown_callback',
      'wrapper' => 'dropdown-second-replace',
    ),
  ];

Referenced many links but cannot find a solution to resolve this issue.

References:

https://www.drupal.org/node/586576

populate drop down from results using ajax

http://techqa.info/drupal/question/203725/help-understand/solve-this-warning:-invalid-argument-supplied-for-foreach%28%29-in-views-that-requires-class-registry-clean-to-mend

0

Looking on the code i suspect that error lies in these lines- $selected = isset($auktion->zip_code) ? $auktion->zip_code : NULL; $selected = isset($form_state['values']['zip_code']) ? $form_state['values']['zip_code'] : $selected; $ort_options = _ajax_city_dropdown_options($selected);

And according to my understanding adding these lines will fix this warning-

 $selected = isset($auktion->zip_code) ? $auktion->zip_code : NULL;
$selected = isset($form_state['values']['zip_code']) ? $form_state['values']['zip_code'] : $selected;
$ort_options = _ajax_city_dropdown_options($selected);
if(!is_array($ort_options)){
    $ort_options=array();
}

Assuming that _ajax_city_dropdown_options($selected); returns options for second select list/ Check Boxes there can be some options in first Select List or there is none selected in first list for which there is no values available for second list. So returning an empty array will address this situation and prevent this error form appearing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.