Need to force #default_value for AJAX tableselect checkboxes

by Joe Beuckman   Last Updated August 13, 2019 02:07 AM - source

I built a drop-down ajax pager that replaces a tableselect with the requested page of rows. The array of selected item IDs is stored in a hidden field and that logic is working across entity load/save and AJAX replacements.

When the form initially loads, my tableselect #default_value operates correctly and checks the selected rows on the first page. But after AJAX paging through the big list to a different page and back, the checkboxes aren't checked again.

I think this has to do with #default_value only working before the form has been submitted. How can I reset the state so that my updated tableselect #default_value is used after AJAX?

Tags : forms ajax theming


Answers 2


Just before the tableselect's array in the form builder function, put the following code:

unset($form_state['input']['my_tableselect']);
Joe Beuckman
Joe Beuckman
March 10, 2012 15:14 PM

For those ones experiencing the same case in Drupal 8, this is the equivalent solution:

$user_input = $form_state->getUserInput();
unset($user_input['my_tableselect']);
$form_state->setUserInput($user_input);
camilo.escobar
camilo.escobar
August 13, 2019 01:22 AM

Related Questions


How to keep modal open after form submission?

Updated August 20, 2016 09:03 AM


Update a form element with Ajax

Updated November 13, 2017 21:07 PM

Change mark-up with a textfield using Ajax

Updated June 15, 2018 08:07 AM

Table doesn't render on ajax command

Updated August 02, 2018 21:07 PM