This patch adds a new option for "afterSubmit" to hook_popups(). The "afterSubmit" option makes it possible to call a JavaScript function after successful submission of a form through a popup. We're using popups to dynamically update multiple parts of the page at once, so the existing targetSelectors option is not enough. Adding a custom callback allows us to make any changes we desire with the returned data manually, rather than depending on popups to simply inject the new content into the page for us.

If desired, the afterSubmit callback can return the value "false", and skip all remaining processing normally done by popups.

Comments

starbow’s picture

I like it.
I am curious where the targetSelectors option falls short. You know it accepts a hash as input right?

quicksketch’s picture

Hmm, I realized this patch isn't even going to be much help to me. In a previous version of popups.js, the DOM object for the link that was clicked was passed into the Drupal.popups.formSuccess() function as a third parameter "a". Without it, this patch doesn't add a lot of value.

The scenario we had was configuring blocks on the page, inline. A "configure" link was added to every block on the page using a single selector "a.block-edit". The problem was after the block had been reconfigured, we needed to update that block with the new contents of the block. We used the "a" parameter to identify which link had been clicked on and therefor which block had just been edited. We'd find the parent DIV containing the block and update it with the new contents of the block.

So I'm moving this to code needs work, since you're right, it doesn't do anything new without knowing contextual information about what was actually clicked.

quicksketch’s picture

Status: Needs review » Needs work
quicksketch’s picture

StatusFileSize
new3.29 KB

Here we are, this re-instates the "a" parameter that was removed several revisions of popups ago. My guess is that popups.js never needed the "a" parameter, so it was just taken out to clean things up a bit. However, in our case it'd be very helpful to have that information when running a custom afterSubmit function.

quicksketch’s picture

Status: Needs work » Needs review
StatusFileSize
new2.81 KB

That last patch had a small bit of unnecessary cruft. Here we are again.

starbow’s picture

Status: Needs review » Needs work

Hmm, ok, I get how this is useful if you have context. You can't name the variable 'a' though. One of nedjo's patches made it possible to trigger popups on any type of element. So the obvious variable name is 'element', but you will have to make sure that 'element' isn't already being used in one of those function.

quicksketch’s picture

Status: Needs work » Needs review
StatusFileSize
new2.85 KB

Seems like "element" was free in all contexts, here's a reroll.

starbow’s picture

Status: Needs review » Needs work

It passes my hairy eyeball test, but I still try it out.
Can you reroll against D6-dev when it becomes available?

quicksketch’s picture

Status: Needs work » Needs review
StatusFileSize
new786 bytes

Here's a reroll against the latest CVS.

starbow’s picture

Status: Needs review » Needs work

That looks like a reroll of the original patch, not the improved one from #7.

quicksketch’s picture

Status: Needs work » Needs review
StatusFileSize
new2.92 KB

I'm a dunce. I uploaded the wrong file. :P

starbow’s picture

Status: Needs review » Needs work

Ok, I am branching to 6--2 for this patch and #336641: Auto-load needed JS and CSS files (and settings). The 6--1 is now closed to new features and will be just for bug fixes. Of course, I added a bunch of new comments and code cleanups before branching, and now this doesn't apply any more. Sorry.

Also, in Drupal.popups.formSuccess
Drupal.popups.openContent(data.title, data.messages + data.content, options);
should probably be
Drupal.popups.openContent(data.title, data.messages + data.content, options, element);

sirkitree’s picture

Version: 6.x-1.1-rc7 » 6.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new3.1 KB

Hey guys! I found I need this function pretty badly unless I wanna keep using popups-form-reload, in which case my status messages aren't retained. So here's the patch rolled against the latest 6.x-2.x-dev

I just manually read Nate's patch and also took into account your suggestion in #12 Tao.

sirkitree’s picture

Looks like I did something wrong here... #popups element is being duplicated with this patch... hrm

sirkitree’s picture

also, this is not available when trying to use on-popups-options and should be documented as such.

sirkitree’s picture

StatusFileSize
new3.09 KB

I see what went wrong here, there was a line you had commented out that I uncommented. This was causing the dup. Here's a revised patch that so far seems to be working correctly for me.

starbow’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev
Status: Needs review » Fixed

Ok, I still haven't really wrapped my brain around the js/css loading stuff over in 2.x-dev, so I have wrapped this patch into the upcoming 1.2. It fits in with the lifecycle event triggers I am playing around with (which, might be a better way to get the same effect, but I don't have any afterSubmit callbacks to test, so I am not sure).

Status: Fixed » Closed (fixed)

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

kristen pol’s picture

Is there an example of how to use this? If you have an after submit function that returns false, will the normal redirection occur for the popup... for example, if if the popup is the login form and you are on some random page, will it redirect you to the page the login form normally redirects you to?

I'm trying to figure out how to get a popup to redirect to where it normally goes and am hoping this will help. There was information here: http://drupal.org/node/455894 about hijackDestination yet I'm not seeing that in the code anymore.

Kristen