2

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?

0

2 Answers 2

4

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

unset($form_state['input']['my_tableselect']);
2
  • Wow dude I checked your solution. And it's the only one which is working. I just looked into this discussion (drupal.org/node/1458824) that this is actually a core bug. But your line and all is working fine. Great man. Thank you so much. :)
    – kwoxer
    Commented Apr 5, 2016 at 12:59
  • Btw for me it was unset($form_state['input']['table']); because my table is called in another way. And I called it in the custom submit callback at the very begin.
    – kwoxer
    Commented Apr 5, 2016 at 13:13
0

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.