This patch makes it possible to use a custom success callbacks for AHAH request performed via ahah.js. This is completely optional and current default behaviour is not changed at all, but adds much more flexibilty to ahah.js and makes it usable in many more situations.
This patch adds a new, optional key to the #ahah element property: success_callback. If set, it has to be the name of a function in the Drupal.ahah.prototype.successCallbacks namespace. Then, the specified function is called instead of the default success callback (which remains exactly as it used to be: it inserts the new content into the page based on the 'wrapper' and 'method' settings).
I needed this for the searchable-modules-page-with-vertical-tabs-patch, and it will be useful in many other situations. Also, this moves ahah.js a bit more in the direction of ctools/views ajax stuff, which is a good thing (tm) IMO.
Comment | File | Size | Author |
---|---|---|---|
#13 | 396466_ahah_public-13.patch | 3.41 KB | stBorchert |
#11 | 396466_ahah_public-12.patch | 3.19 KB | stBorchert |
#10 | 396466_ahah_public-10.patch | 3.18 KB | stBorchert |
#7 | ahah_public_2.patch | 3.3 KB | Frando |
#5 | ahah_public.patch | 3.3 KB | Frando |
Comments
Comment #1
Frando CreditAttribution: Frando commentedSee http://drupal.org/node/396478 for an example on how this can be used.
Comment #2
quicksketchI understand where this patch is coming from and why we need it, however I'm not sure it's the right approach. We've already introduced "#ahah['callback']" (see #360128: Security fix for simplified AHAH callbacks), so having something called "success_callback" could be confusing when one of them refers to a JavaScript callback and the other one refers to a PHP callback.
Since this patch is intended to provide functionality only in the JavaScript layer, it'd make sense to make the solution purely JavaScript based. We've already setup AHAH objects, but unfortunately they're not actually available anywhere.
This small patch simply makes the AHAH object public, so you can override any of the methods (such as beforeSubmit, success, and error).
An example for a button with the ID "edit-more":
Comment #3
BoarK CreditAttribution: BoarK commentedTo keep with spirit of sticking to the domain of javascript, I added the following to ahah.js after applying patch #2.
Add this code in Drupal.ahah.prototype.success
This allows for:
without by-passing the default ahah success callback.
Comment #4
apadernoComment #5
Frando CreditAttribution: Frando commentedHere is a new version of the patch that is based on quicksketch's suggestion.
It is indeed that simple, by making the ahah objects publicly accesible it is possible to override all handler functions (success, error, ..).
I added some documentation, and splitted the success function in two parts, one that handles general success processing (removing the throbber, restoring the form properties) and a new function, Drupal.ahah.insertNewContent that actually inserts the new content into the page. This makes it possible to override just the part where the new content is inserted, which will most likely the most common use case, and so you don't have to copy paste the general success processing code here.
But basically, this patch just adds two lines of code to make the ahah objects public, adds some documentation and moves some code a little bit around. No other changes.
These *very* simple changes add a lot more flexibility to ahah.js and will make it usable in quite a few more situations than it is currently.
Comment #7
Frando CreditAttribution: Frando commentedRerolled for changes in HEAD.
Comment #9
liquixis CreditAttribution: liquixis commentedsubscribing
Comment #10
stBorchertRe-roll against HEAD (actually against the latest dev release, because I've no access to cvs from here).
Comment #11
stBorchertAh, diffed from wrong directory. No it should pass.
Comment #13
stBorchertOk, now for real.
Comment #14
quicksketchPatch doesn't break any functionality and adds a lot of needed flexibility. We're doing this same approach in Drupal.tableDrag[keyName], and it's been working well for the Drupal 6 release cycle. I applied the patch and tested the following:
- Table drag
- CCK "more" button
- Poll "more" button
- Resizeable textareas
This patch doesn't change any functional code, it just moves it to a separate function.
Comment #15
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #16
quicksketchAwesome! Thanks Dries.
Comment #18
bmhaskar CreditAttribution: bmhaskar commented@Dries: Is this patch available in version 6.19?
I downloaded Drupal's 6.19 version from drupal.org yet I had to apply this patch.
Comment #19
supadits CreditAttribution: supadits commentedapply #2 and #3 work nice on 6.20
Comment #20
jozzhart CreditAttribution: jozzhart commented#13: 396466_ahah_public-13.patch queued for re-testing.
Comment #22
jozzhart CreditAttribution: jozzhart commented#2: drupal_ahah_objects.patch queued for re-testing.
Comment #23
charlie-s CreditAttribution: charlie-s commentedbmhaskar changed this to 6.20 as a bug report. Spent a bit of time trying to get this working on 6.x before I realized this is intended for 7. Can someone confirm and update the status / close this thing?
Comment #24
nod_Well, that's not going to make it to 6 and the functionality is already available in 7.x
I'll just mark it fixed to let people read it just in case.
Comment #25
tema_u CreditAttribution: tema_u commentedahah_success_callbacks_frh.patch queued for re-testing.
Comment #26
ionmedia CreditAttribution: ionmedia commentedi have a form with cck filefield and i want to trigger ajaxtrigger after file was successfully uploaded to server.
all what i need is event in my js, how i can do it without changing ahah.js ?
Comment #27
cweagansSupport requests are neither major nor critical.