Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have been finding out many users who are having trouble with running #ajax with tableselect, and it seems the problem is specifically when one uses checkboxes.
When a tableselect is created with multiple = false, which means radios buttons on the left column, the #ajax attribute works fine. However with multiple = true, the #ajax attribute doesn't do anything.
Comment | File | Size | Author |
---|---|---|---|
#50 | 1458824-50.patch | 2.98 KB | therealssj |
#46 | 1458824-46.patch | 476 bytes | therealssj |
#46 | 1458824-46-tests-only.patch | 2.51 KB | therealssj |
#39 | drupal-tableselect-ajax-checkboxes-1458824-39.patch | 476 bytes | mayaz17 |
#31 | 1458824-31.patch | 3.6 KB | idebr |
Comments
Comment #1
Henrik Opel CreditAttribution: Henrik Opel commentedI can confirm the problem. Looking at
form_process_tableselect()
in form.inc shows that the line which passes the '#ajax' property on to the created child elements is only present in the 'radios' related else part of the if clause, but absent for the default checkbox creation part. Adding the line there fixes the problem on first sight - not sure if this has some negative effects and was left out on purpose, but I doubt that.The attached patch does just that - add the '#ajax' property passing line from the 'radios' related part to the 'checkboxes' related one as well.
Comment #2
jbeuckm CreditAttribution: jbeuckm commentedThis patch works without a pager. However, I have a pager for this tableselect and after paging, the ajax handler is only called on the first checkbox clicked. Subsequent clicks do not fire the checkbox ajax.
UPDATE: This was due to my ajax form causing "An illegal choice has been detected. Please contact the site administrator." -- which I haven't solved yet.
UPDATE2: Hours later, I'm using my own custom ajax pager, which causes the same "illegal choice" error with my dynamically generated options. ['#validated']= TRUE; successfully suppresses the drupal form security feature that was balking at my changed form option values.
Comment #3
jbeuckm CreditAttribution: jbeuckm commentedI have SimpleTests that are failing without this patch. What is the best practice for continuing to SimpleTest my modules until this patch is merged into core?
Comment #4
ashishdalvi#1: drupal-tableselect-ajax-checkboxes-123456-1.patch queued for re-testing.
Comment #5
kevinquillen CreditAttribution: kevinquillen commentedJust a follow up on the patch, it works fine if there is no pager.
If you do not have a paged display, it correctly attaches the AJAX callback and properties.
Comment #6
JvE CreditAttribution: JvE commentedRolled a patch for D8 to get it fixed there and marking for backport to D7.
I think the whole tableselect code could do with a review, but let's get the real problems like this fixed first.
This patch will make #ajax work for for checkboxes, but not for the "select all" checkbox that comes with them. This is probably a good thing, but something to be aware of.
Comment #7
nod_@jbeuckm could you post your tests here?
Patch is using tabs.
Other than that it looks good but it needs tests.
Comment #8
nod_Comment #9
JvE CreditAttribution: JvE commentedOkay, my first attempt at tests.
One without fix which should fail and one with fix which should pass.
Comment #10
cosmicdreams CreditAttribution: cosmicdreams commented#9: drupal-tableselect-ajax-fixntest-1458824-9.patch queued for re-testing.
Comment #12
JvE CreditAttribution: JvE commentedRe-rolled for file location changes.
Comment #13
orbistertius CreditAttribution: orbistertius commentedThis fixes the ajax callback if you select one of the options but if you select the "all" checkbox in the table header nothing happens like mentioned in #6. I know that this is an old bug report but it would be nice to get this fixed, please.
Comment #14
mayaz17 CreditAttribution: mayaz17 commentedUpdated the patch for the current 7.x core version
Comment #16
learnbydrop CreditAttribution: learnbydrop commentedHi,
I written a module with table select form element, but when I search a value with ajax, the tableselect is not showing results.
To resolve this issue, I utilize "form_process_tableselect", so the result is showing perfectly.
But the issue is, when I get search results, I don't perform any action on the results.
Procedure:
1. Form showing new post button ( to add the records )
2. table showing the records with tableselect element
3. Update button working to update the status
4. search a value with search field and button
No results are showing.
Modifications are added in the module like:
$form_html = drupal_render($form['list_form_items']);
changed this line with
$form_html = form_process_tableselect($form['list_form_items']);
4. results are showing, but when I select the check box for status update its not working.
Please check the code and let me know solutions
Example 1: ( no results are showing)
After modifications results are showing:
Update Status feature is not working
find the screen shots ::
Comment #18
presleyd CreditAttribution: presleyd commentedPatch in 14 has been working for me for over a year now.
Comment #19
kevinquillen CreditAttribution: kevinquillen commentedI concur, that patch is also working perfectly for me and has been used on half a dozen forms with tableselect AJAX inputs.
Comment #20
dcam CreditAttribution: dcam commentedRe-setting the version back to Drupal 8. Issues must be fixed for the current development version first, then backported.
It looks like there is an 8.x patch in #12. I'm guessing it won't apply anymore, but I'll re-test it next.
Comment #23
dcam CreditAttribution: dcam commented#12 needs to be rerolled.
Comment #24
idebr CreditAttribution: idebr commentedComment #25
idebr CreditAttribution: idebr commentedComment #28
idebr CreditAttribution: idebr commentedI replaced the call to
drupalPostAJAX()
with the newdrupalPostAjaxForm()
Comment #31
idebr CreditAttribution: idebr commentedDid the empty ajax callback ever pass the testbot? Anyway, I added a valid one.
Comment #33
omarlopesinoI applied the patch of mayaz17 (#14) and it worked for me.
Comment #35
jhedstromPatch no longer applies.
Comment #36
cwoky CreditAttribution: cwoky as a volunteer and at Smile commentedI rerolled the patch 1458824-31.patch (#31)
Comment #37
gcardinal CreditAttribution: gcardinal commentedTested 1458824-36.patch and it doesn't seem to work. Also it is not possible to add radios / checkboxes within FormStateInterface on #ajax callback.
Comment #38
lokapujyaAccording to the provided test, the AJAX works now with the patch. We use table select with checkboxes in multiple places in Core, but not combined with AJAX. I can't find anything wrong. Possibly the test could do something more than just verifying that the AJAX was executed. The array() can be updated to []. But, I don't see a specific reason mentioned in #37 why this should be "Needs work".
Comment #39
mayaz17 CreditAttribution: mayaz17 commentedI updated the patch to work with the current version 7.43
Comment #40
lokapujyaFor a better assert.
Comment #41
lokapujyaOn second thought, the test is ok, this isn't about testing AJAX, just that AJAX is working. So RTBC #36.
Comment #42
alexpottCommitted #36 / f6bfa62 and pushed to 8.0.x, 8.1.x and 8.2.x. Thanks!
Comment #45
kevinquillen CreditAttribution: kevinquillen at Velir commentedWOOO!
Comment #46
therealssj CreditAttribution: therealssj commentedPatch + Tests For 7.x
Comment #47
therealssj CreditAttribution: therealssj commentedComment #49
lokapujyaThe patch should have the tests.
Comment #50
therealssj CreditAttribution: therealssj commentedPatch with tests.
Comment #51
therealssj CreditAttribution: therealssj commentedComment #53
therealssj CreditAttribution: therealssj commentedI am not sure why the test fails.
It works on simplytest and even in local environment.
Comment #54
lokapujyaComment #57
lokapujyaThis has got to be good for D7; It's the same fix. Can any of the original commenters confirm that this fixes their issue?
Comment #60
kwoxer CreditAttribution: kwoxer as a volunteer and commentedToday I was facing the same issue. I have a custom button which does some database stuff and finally adding a new element via Ajax to a tableselect list. Works great so far. Just the the checkboxes are now correctly enabled, though they are enabled. When reloading it is correctly. So abviously a refreshing bug.
I tested so many stuff. And finally I found this one here. So it's a real issue anyway. At least it was not my fault in defining the form. I just tested
unset($form_state['input']['my_tableselect']);
and it instantly worked.So yeah give it a try. It will just be fixed in Drupal 8. Is this correct? Or will there also be a fix in Drupal 7?
Hope I could help someone here with Drupal 7.
Comment #61
dddave CreditAttribution: dddave commentedSorry @kwoxer but overzealous Mollom unpublished your posts.
Comment #62
kwoxer CreditAttribution: kwoxer as a volunteer and commentedReally sad. Because there was always the message, post successfully. Finally it's published. It's ok.
Maybe it was because I had a link to Stackoverflow at the very first. But now it's just the code. I think that's ok, too. :)
Comment #63
lokapujyaIt is committed to Drupal 8. Someone needs to test the Drupal 7 patch in comment #50 and move the issue to RTBC. Then, it may be committed to Drupal 7.
@kwoxer: Thank you for adding that solution. But, what you describe in #60 doesn't seem to be the exact same problem that this issue is about. Actually, it doesn't even seem like a bug; Seems like you just needed to add that code to unset the $form_state for your specific problem. This issue is specifically about the #ajax not even triggering.
Comment #64
kwoxer CreditAttribution: kwoxer commentedActually my issue was this one here: http://drupal.stackexchange.com/questions/25131/need-to-force-default-va...
But I reread the description here, that says: "When a tableselect is created with multiple = false, which means radios buttons on the left column, the #ajax attribute works fine. However with multiple = true, the #ajax attribute doesn't do anything.".
This sounds like exactly my issue. :)
As I said, the form_state did not set the checkbox states for me.
Sorry when it's the wrong issue here. But I landed here and maybe someone else with my issue.
Comment #65
botrisTested this patch and it works.
I have:
Without patch nothing happens, with patch ajax callback get's triggered.
Comment #66
presleyd CreditAttribution: presleyd commentedWe also use this patch on 7 and it works for us. My vote for rtbc status.
Comment #67
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedRTBC + 1, looks good to me, straightforward bug fix and if this really conflicted somewhere it can still be work-around'ed.
Marked for commit.
Comment #68
stefan.r CreditAttribution: stefan.r commentedComment #69
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedCommitted and pushed to 7.x! Thanks!