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?

up vote 3 down vote accepted

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

unset($form_state['input']['my_tableselect']);
  • 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 Apr 5 '16 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 Apr 5 '16 at 13:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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