It seems that #ajax['method'] doesn't work at all in Drupal 7.
The documented intent of 'method' is to allow returned text to append, prepend, before, or after the named wrapper. However, since we changed to ALWAYS replace the named wrapper, I'm not sure this is even possible.
What I expect: In #ajax, if I set up like this
$form['checkbox'] = array(
'#type' => 'checkbox',
'#ajax' => array(
'wrapper' => 'ajax_bug_demos_non_ajax_submit_status',
'callback' => 'ajax_bug_demos_non_ajax_submit_callback',
'method' => 'after',
),
'#suffix' => '<div id="ajax_bug_demos_non_ajax_submit_status">Original status</div>',
);
the text returned by the callback should be placed after the existing text.
What happens instead:
The text returned by the callback always replaces the existing wrapper.
It may be that we can't do anything about this, in which case we'll have to change the documentation and note in the upgrade guide.
Comment | File | Size | Author |
---|---|---|---|
#19 | drupal.ajax_method_645800_19.patch | 10.84 KB | effulgentsia |
#15 | drupal.ajax_method_645800_15.patch | 11 KB | katbailey |
#13 | drupal.ajax_method_645800_13.patch | 10.97 KB | katbailey |
#11 | drupal.ajax_method_645800_10.patch | 10.82 KB | katbailey |
#3 | drupal.ajax_method_645800_03.patch | 9.67 KB | rfay |
Comments
Comment #1
effulgentsia CreditAttribution: effulgentsia commentedThis is an unintended side-effect of the AJAX framework upgrade, and ideally should be fixed. I believe this patch fixes it. @rfay: can you add a test to this patch?
Comment #2
rfayI'll see if I can roll a bogo-test. Thanks for the work on this.
Comment #3
rfayWell, this gives us back #ajax['method'] - thanks effulgentsia.
This patch adds a test for the new insert command. It's a poor test, as we don't have a good end-to-end javascript test methodology yet. It does at least test some of the code.
I also tested the live ajax version in ajax_form_test module and the Examples module AJAX commands section and saw no regressions, and stepped through the server side and looked at the JSON delivered to firefox. It all looks good to me. While testing, I tried 'prepend', 'append', and 'replace' as the the #ajax['method'] used in the calling form element, and those worked right too.
+1
Comment #4
katbailey CreditAttribution: katbailey commentedThis looks good to me - I tested it using the Quick Tabs admin form and everything worked as it should (tried various methods). One thing I noticed is that in ajax.js, we have
But surely response.method will always be null because of how ajax_command_insert is defined, i.e.
Therefore, in the js code, shouldn't it just be var method = ajax.method?
Comment #5
effulgentsia CreditAttribution: effulgentsia commentedThanks! Some of the other ajax_command_*() functions (such as ajax_command_replace()) return a 'command' => 'insert' and a 'method' => SOMETHING. That's why response.method is checked in ajax.js.
Comment #6
katbailey CreditAttribution: katbailey commentedOK, ignore that last comment - I didn't realise that Drupal.ajax.prototype.commands.insert() is used by ajax_command_prepend() as well as ajax_command_insert(). Still playing around with it...
Comment #7
katbailey CreditAttribution: katbailey commented@effulgentsia - thanks, cross-posted ;-)
Finished playing around - works perfectly :-)
Comment #8
sunBut _replace() is not removed in this patch?
Either move this comment above the remarked line or drop it and clarify the PHPDoc instead.
Which kind of BC is meant here? D6 or D7? Either way, I'd say we can drop this. Yet, we are in alpha, not beta.
Wrong indentation here.
Wasn't the patch changing the #properties already committed?
Powered by Dreditor.
Comment #9
effulgentsia CreditAttribution: effulgentsia commentedCNW for #8. Am hoping to get to it soon.
Comment #11
katbailey CreditAttribution: katbailey commentedRerolled as per sun's comments in #8.
Comment #13
katbailey CreditAttribution: katbailey commentedAdjusted the test as necessary...
Comment #14
sunTrailing white-space.
Powered by Dreditor.
Comment #15
katbailey CreditAttribution: katbailey commentedNo more trailing white-space.
Comment #16
katbailey CreditAttribution: katbailey commentedComment #17
sunLooks good to me. I hope that effulgentsia can approve this patch and RTBC.
Comment #18
effulgentsia CreditAttribution: effulgentsia commentedRe #8:
With the #15 patch dropping the suggested hunk, we are introducing a BC break. Any module that is setting #ajax['method'] to 'replace' (instead of 'replaceWith' or NULL) won't work any more. This patch removes the redundant setting of 'method' from field, file, and poll modules, but is this an acceptable break to contrib modules? It is quite likely that there is some D7 contrib module out there using 'method' => 'replace'.
Comment #19
effulgentsia CreditAttribution: effulgentsia commentedThis adds the following hunk to ajax_process_form() to maintain BC:
I think this is better than #3 which did the equivalent in ajax.js, but maybe that's just my bias towards preferring cruft in PHP rather than in JS.
Comment #20
sunI just started to play with something weird (effulgentsia knows what) and stumbled over this issue.
Problem is: #ajax[wrapper], without anything else, defines a "wrapper", not an "element to replace", but totally a wrapping bounding box.
When using #ajax[wrapper], the entire element is replaced currently. Therefore, you can't use #ajax on links and stuff - without specifying "replace" as method (...somehow...).
This patch properly fixes the bug and my fancy code starts to work.
Comment #21
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.