Commit f6bfa62c authored by Alex Pott's avatar Alex Pott
Browse files

Issue #1458824 by idebr, JvE, mayaz17, cwoky, Henrik Opel: Ajax doesn't work...

Issue #1458824 by idebr, JvE, mayaz17, cwoky, Henrik Opel: Ajax doesn't work with Tableselect with checkboxes

(cherry picked from commit e6579987)
(cherry picked from commit 90486934)
parent 67483159
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -259,6 +259,7 @@ public static function processTableselect(&$element, FormStateInterface $form_st
              '#return_value' => $key,
              '#default_value' => isset($value[$key]) ? $key : NULL,
              '#attributes' => $element['#attributes'],
              '#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
            );
          }
          else {
+21 −0
Original line number Diff line number Diff line
@@ -42,6 +42,27 @@ function testMultipleTrue() {
    }
  }

  /**
   * Test the presence of ajax functionality for all options.
   */
  function testAjax() {
    $rows = array('row1', 'row2', 'row3');
    // Test checkboxes (#multiple == TRUE).
    foreach ($rows as $row) {
      $element = 'tableselect[' . $row . ']';
      $edit = array($element => TRUE);
      $result = $this->drupalPostAjaxForm('form_test/tableselect/multiple-true', $edit, $element);
      $this->assertFalse(empty($result), t('Ajax triggers on checkbox for @row.', array('@row' => $row)));
    }
    // Test radios (#multiple == FALSE).
    $element = 'tableselect';
    foreach ($rows as $row) {
      $edit = array($element => $row);
      $result = $this->drupalPostAjaxForm('form_test/tableselect/multiple-false', $edit, $element);
      $this->assertFalse(empty($result), t('Ajax triggers on radio for @row.', array('@row' => $row)));
    }
  }

  /**
   * Test the display of radios when #multiple is FALSE.
   */
+7 −0
Original line number Diff line number Diff line
@@ -104,3 +104,10 @@ function form_test_form_form_test_vertical_tabs_access_form_alter(&$form, &$form
  $form['fieldset1']['#access'] = FALSE;
  $form['container']['#access'] = FALSE;
}

/**
 * Ajax callback that returns the form element.
 */
function form_test_tableselect_ajax_callback($form, FormStateInterface $form_state) {
  return $form['tableselect'];
}
+6 −0
Original line number Diff line number Diff line
@@ -34,11 +34,17 @@ function tableselectFormBuilder($form, FormStateInterface $form_state, $element_
    $form['tableselect'] = $element_properties;

    $form['tableselect'] += array(
      '#prefix' => '<div id="tableselect-wrapper">',
      '#suffix' => '</div>',
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $options,
      '#multiple' => FALSE,
      '#empty' => t('Empty text.'),
      '#ajax' => array(
        'callback' => 'form_test_tableselect_ajax_callback',
        'wrapper' => 'tableselect-wrapper',
      ),
    );

    $form['submit'] = array(