1 ajax_forms_test.module ajax_forms_test_validation_form($form, &$form_state)

This form and its related submit and callback functions demonstrate not validating another form element when a single Ajax element is triggered.

The "driver_text" element is an Ajax-enabled textfield, free-form. The "required_field" element is a textfield marked required.

The correct behavior is that the Ajax-enabled driver_text element should be able to trigger without causing validation of the "required_field".

File

core/modules/simpletest/tests/ajax_forms_test.module, line 436
Simpletest mock module for Ajax forms testing.

Code

function ajax_forms_test_validation_form($form, &$form_state) {

  $form['driver_text'] = array(
    '#title' => t('AJAX-enabled textfield.'),
    '#description' => t("When this one AJAX-triggers and the spare required field is empty, you should not get an error."),
    '#type' => 'textfield',
    '#default_value' => !empty($form_state['values']['driver_text']) ? $form_state['values']['driver_text'] : "",
    '#ajax' => array(
      'callback' => 'ajax_forms_test_validation_form_callback',
      'wrapper' => 'message_area',
      'method' => 'replace',
    ),
    '#suffix' => '<div id="message_area"></div>',
  );

  $form['spare_required_field'] = array(
    '#title' => t("Spare Required Field"),
    '#type' => 'textfield',
    '#required' => TRUE,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  return $form;
}