When AHAH is attached to a button, but 'selector' is set, sometimes you need the button.

Normally, it'd be in $form_state['clicked_button'], but that's not possible to find without an op.

This patch fixes that by adding an "op" option if it's added to the element.

Used by http://drupal.org/node/193191, you can get some pretty cool stuff going.

It also upgrades the version of jquery.form.js to 2.0.1

CommentFileSizeAuthor
#2 form_ahah_op.patch14.39 KBquicksketch
form_ahah_op.patch14.71 KBdmitrig01
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eaton’s picture

Title: AHAH does not send the OP of a form » AHAH does not send the clicked button

I haven't had time to test this exhaustively, but it's worth noting that it does NOT in fact set the op directly (which would be bad). It respects the specific button's #name property, which FAPI uses to match the clicked button even if $item['#name'] = 'op' has been changed manually, or if the button in question is an image button.

quicksketch’s picture

FileSize
14.39 KB

This is definitely a welcome improvement. It does two things: 1) it sends the button name and value, that's very important considering $_POST['op'] has been killed. 2) It also sets up a best practice for attaching your #ahah behaviors. Because the ahah request is supposed to mimic the behavior when a button is clicked without ahah, it makes the handling code on the server-side easier (or possible at all).

So a big thumbs up to this improvement. Two minor semantic changes though.

I shorted the if statement in ahah.js to this:
this.button = element_settings.button || { };

And the code to add a button to the settings to this:
'button' => $element['#type'] == 'submit' ? array($element['#name'] => $element['#value']) : FALSE,

Basically just shortening up some things where a quicker approach was available.

I tested the patch with upload.module to make sure the new version of jquery.form.js didn't break anything and it looked solid. Further, I unapplied the drag and drop blocks patch to test the AHAH version of the blocks page with it and it worked well also. I think we can trust that at the very least, this patch does no harm.

I applied http://drupal.org/node/193191 and http://drupal.org/node/191360 (parent menu choosers or drill-down) to test out the functionality in action and it works great. This is RTBC in my opinion.

chx’s picture

Status: Needs review » Reviewed & tested by the community

I am OK with this -- and I need it, even.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.