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.
Hello,
I am trying to find the best way to reload the parent page when a modal has been closed.
There is a related issue, but it doesn't seem to work in this case. The related issue is here: http://drupal.org/node/561788
I have tried doing it in jQuery directly, but because the dialog modal is created by ctools, it is not working as expected. So I need to create a command to reload the page when the modal has just closed. Any one done this, or have any ideas of the best way to do it?
Comment | File | Size | Author |
---|---|---|---|
#11 | ctools-modal_close_behavior-826786-11.patch | 766 bytes | ron_s |
#7 | 826786-7-ctools-modal_close_behavior.patch | 509 bytes | pfrenssen |
Comments
Comment #1
blairski CreditAttribution: blairski commentedJust to add to this, I have now achieved the desired effect in jQuery. Here is the code:
So essentially I am replacing the exisiting close button (the X in the top right corner of the modal) with my own which has an event handler attached. It works, but it would be better to do it in CTools as a command.
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedI don't think you really want to do this when the modal is closed; don't you want to do this only when the modal has successfully completed? Using the close button usually indicates a cancel and it should return to the previous state.
The server can send ctools_ajax_command_reload() instead of a ctools_ajax_command_dismiss() to do a reload when whatever is in the modal is complete.
Also, the jquery you're using affects the jQuery UI dialog, not the CTools modal. Maybe you're actually using dialog.module?
Comment #3
blairski CreditAttribution: blairski commentedWe have a specfic reason why we need the page to reload on close. Basically the modal has a product form where the user can find and add a product, but they can keep adding more and more if they like in a loop, so the modal doesn't complete in a normal way. When the user has finshed, they close the modal, but need to see an update page based on what they added in the modal. I thought others might have a similar requirement.
But we have since decided that reloading the page is not the best experience, so we are now going to update the page via Ajax, so it seems this won't be necessary.
And yes, we are using the dialog module along with ctools. But I thought we could use a ctools command with dialog modal.
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedI definitely agree that using AJAX to add the items to the page is the better experience than reloading the page.
Comment #6
travist CreditAttribution: travist commentedJust some documentation on what I consider the best way to do this...
That worked beautifully for me... Hope this helps someone in the future.
Comment #7
pfrenssenThe above only works when the "Cancel" button is clicked in a multistep form made with the form wizard, not in regular modals. I'm reopening this as I am also looking for a way to react to a modal being closed.
Can't this be solved rather easily by triggering a behavior? Currently the 'CToolsDetachBehaviors' fire when the modal is closed, but unfortunately these also fire when the modal is dismissed due to a form being successfully submitted. This cannot be used if an action should only occur when closing, not when submitting.
Attached patch adds this behavior. You can then run whatever javascript you want by implementing the behavior, eg:
Comment #8
pfrenssenComment #10
firewaller CreditAttribution: firewaller commentedI know this is old, but the functionality would be very helpful. Patch #7 works for me, but fires a bunch of times.
Comment #11
ron_s CreditAttribution: ron_s commentedAha! This patch is exactly what I needed.
Here is our issue: We're using Ajax Facets in a ctools modal window to allow users to filter information without needing to reload another page. Ajax Facets does its filtering by changing the URL of the originating page.
If Ajax Facets is being used on a standard search page, this would be ok, because it's changing the URL from something like
/search
to/search?f[]=type:blog
. However, when using Ajax Facets within a modal, this becomes a problem because the underlying page's URL is changed from/blog/my-blog
to/search-modal?f[]=type:blog
. Once the modal is closed, the URL is still at "search-modal" even though the user is on the blog page.An easy way to fix this is to reset the browser's URL path using
window.history.pushState
when the modal is closed. The patch in #7 lets me do exactly that.The previous patch no longer applies since there have been some changes to ctools since it was first created. I've attached a new version for review.
Please set to RTBC if others agree with adding this. Thanks.
Comment #12
ron_s CreditAttribution: ron_s commented@firewaller, you said it "fired a bunch of times". Can you provide some more details?
I am not seeing that behavior. When I close the modal window it fires once. It does not fire again until I close the modal again.
Comment #13
ron_s CreditAttribution: ron_s commentedPatch #11 still applies cleanly to 7.x-1.17.
Comment #14
joelpittetThanks all! I've committed this to the dev branch for the next release.