Commit e6579987 authored by alexpott's avatar alexpott

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
parent 229b1a53
......@@ -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 {
......
......@@ -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.
*/
......
......@@ -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'];
}
......@@ -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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment