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 "drivertext" 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 drivertext element should be able to trigger without causing validation of the "required_field".


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


function ajax_forms_test_validation_form($form, &$form_state) {

  $form['drivertext'] = 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']['drivertext']) ? $form_state['values']['drivertext'] : "",
    '#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;