Commit f68bbb9a authored by Fabianx's avatar Fabianx

Issue #1458824 by idebr, JvE, therealssj, mayaz17, cwoky, Henrik Opel,...

Issue #1458824 by idebr, JvE, therealssj, mayaz17, cwoky, Henrik Opel, lokapujya, kevinquillen, presleyd, nod_, jbeuckm, botris, mistermoper, gcardinal: Ajax doesn't work with Tableselect with checkboxes
parent 206c7c1b
......@@ -53,6 +53,7 @@ Drupal 7.50, xxxx-xx-xx (development version)
- Increased maxlength of menu link title input fields in the node form and
menu link form from 128 to 255 characters.
- Avoid re-scanning of module directory when a filename or a module is missing.
- Fixed ajax handling for tableselect form elements that use checkboxes.
Drupal 7.44, 2016-06-15
-----------------------
......
......@@ -3545,6 +3545,7 @@ function form_process_tableselect($element) {
'#return_value' => $key,
'#default_value' => isset($value[$key]) ? $key : NULL,
'#attributes' => $element['#attributes'],
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
);
}
else {
......
......@@ -994,6 +994,26 @@ class FormsElementsTableSelectFunctionalTest extends DrupalWebTestCase {
$this->assertTrue(isset($errors['tableselect']), 'Option checker disallows invalid values for radio buttons.');
}
/**
* Test presence of ajax functionality
*/
function testAjax() {
$rows = array('row1', 'row2', 'row3');
// Test checkboxes (#multiple == TRUE).
foreach ($rows as $row) {
$element = 'tableselect[' . $row . ']';
$edit = array($element => TRUE);
$result = $this->drupalPostAJAX('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->drupalPostAjax('form_test/tableselect/multiple-false', $edit, $element);
$this->assertFalse(empty($result), t('Ajax triggers on radio for @row.', array('@row' => $row)));
}
}
/**
* Helper function for the option check test to submit a form while collecting errors.
......
......@@ -589,11 +589,17 @@ function _form_test_tableselect_form_builder($form, $form_state, $element_proper
$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(
......@@ -697,6 +703,13 @@ function _form_test_vertical_tabs_form($form, &$form_state) {
return $form;
}
/**
* Ajax callback that returns the form element.
*/
function _form_test_tableselect_ajax_callback($form, &$form_state) {
return $form['tableselect'];
}
/**
* A multistep form for testing the form storage.
*
......
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