0

I have an AJAX method for when a value is selected from the source drop-down list the target drop-down gets replaced with new values. The problem is that the new replaced drop-down list selected value is not being submitted (e.g. not in $form_state['values']['target'] = 'not the val I selected'). It looks like the value submitted is from the target drop-down list that is default from when the page first loads.

Any ideas as to why this is happening?

function dashboard_node_filter_form(){
  ...
  $form['filters']['source'] = array(
      '#type' => 'select',
      '#options' => source_options(),
      '#title' => 'Source',
      '#ajax' => array(
          'callback' => 'dashboard_node_filter_target',
          'wrapper' => 'edit-target',
          'method' => 'replace',
          'effect' => 'none',
       ),
  );
  // when source is selected this gets replaced
  $form['filters']['target'] = array(
      '#type' => 'select',
      '#options' => get_,
      '#title' => 'Target',
  );
  $form['filters']['submit'] = array(
     '#type' => 'submit',
     '#value' => 'Submit',
  );
}

function dashboard_node_filter_target($form, &$form_state) {
  return $form['filters']['target'] = array(
      '#type' => 'select',
      '#id' => 'edit-target',
      '#options' => display_options($form_state['values']['id']),
  );
}
1

You should make all form manipulations that are supposed to be actually submitted in dashboard_node_filter_form() and use dashboard_node_filter_target() only to tell ajax what part of a form should be updated, and to make aesthetic-only changes that does not affect data.

  • Thanks! This method looks like it will work. Somehow I missed this implementation in the AJAX examples I have found. – dnelson May 14 '13 at 18:45

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.