Problem/Motivation
We are building a site with panelizer ipe and scald used together. Which means that we often open a second modal on the same page.
I know that only a single modal window can be open at a time. Which is fine.
However it seems that CToolsDetachBehaviors and therefore the detach is not called on the first modal when we open the second modal.
Which is a problem when the first modal contained a ckeditor, and then we open the second modal, the detach is not called, and then opening again the first modal, the ckeditor is broken.
Steps to reproduce
- Have scald installed with latest version, and panels with panelizer set up on a content type
- Create a panelized node page
- Customize this page button on the bottom
- Click on the Add new pane button
- Click on New custom content link (will have a ckeditor if ckeditor is set up)
- Click on a link in the dnd (drag and drop library) that would open another ctools modal (like create new atom, or edit / delete on an existing atom)
- This will open a new modal but the detach behaviours are not called on the previous one beforehand
- Close the new modal, and click on Add new pane button again.
- Click on New custom content link
And there the ckeditor will not load and we get JS errors.
A quick dirty workaround is the following:
in modal.js
/**
* Handler to prepare the modal for the response
*/
Drupal.CTools.Modal.clickAjaxLink = function () {
Drupal.CTools.Modal.dismiss();
Drupal.CTools.Modal.show(Drupal.CTools.Modal.getSettings(this));
return false;
};So by dismissing the previous modal before opening the new one, it fixes the problem, but likely there is a better solution.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 2497645-15.patch | 1.21 KB | shubham.prakash |
Comments
Comment #1
merlinofchaos commentedDismissing the previous modal is likely not the correct solution as we often want to have continuity between modals; that would actually close the modal and re-open it while clicking inside the modal.
Instead, in I think the show() method, if the modal is already open, run a detach behaviors there; that'll detach the behaviors on the modal without closing it, and then the new modal can be rendered into it.
Comment #2
nagy.balint commentedI have tried the following:
But unfortunately it does not work.
Even tried to copy paste there the unbind event codes, but it did not help.
Something remains there if the modal is not properly closed.
Likely then this is two issues. One that the CToolsDetachBehaviors was not called, then in theory this code snippet would fix that. But there must be another issue that also happens when pressing cancel in the modal with a ckeditor, that the ckeditor is not correctly cleaned up when detaching, but then thats a different issue, and likely for a different issue queue (#1990224: Problem with Panels IPE).
Comment #3
nagy.balint commentedOkey i found out why it did not work for me.
Because bootstrap theme overrode my modal.js :(
So it actually works fine if i trigger the event there, cause then it will trigger detach in ckeditor.
Patch attached.
However it should also do that when pressing cancel in the custom content form. As currently pressing cancel and then opening the ckeditor again also fails.
Comment #4
nagy.balint commentedOkey this patch works for me, but maybe i have missed something, so any review welcome :)
Comment #5
damienmckenna@merlinofchaos: What do you think?
I'll ask dsnopek to run this through the Panopoly test suite to see if it breaks anything.
Comment #6
nagy.balint commentedAny news here?
Comment #7
maximpodorov commentedThis approach kills the only existing method to respond the events of modal opening and modal closing.
Comment #8
nagy.balint commentedhow so?
Comment #9
maximpodorov commentedBecause CToolsDetachBehaviors is called upon both opening and closing.
Comment #10
aron novakI am not exactly sure to fully understand the problem in #9. but I've found another issue.
Since https://www.drupal.org/files/issues/panels-editor-cache-fix-2238025-05.p... , Panels triggers a click() event on the cancel button for CToolsDetachBehaviors event, but it causes an infinite recursion as the form submit procedure introduced this even triggering.
Modified patch is attached.
Comment #11
maximpodorov commentedWhat is the purpose of CToolsDetachBehaviors? Is it to indicate that the window is closing?
Comment #12
aron novakAs I see, yes. And indeed when we submit it, it's going to be closed, so in my understanding, it's not misleading to have it there, we merely have to prevent infinite loops to handle clicks over and over again.
Comment #13
maximpodorov commentedBut you invoke CToolsDetachBehaviors even if the modal window does not exist.
Comment #14
chris matthews commentedThe 3 year old patch in #10 to modal.js does not apply to the latest ctools 7.x-1.x-dev and (if applicable) needs to be rerolled.
Comment #15
shubham.prakash commentedComment #16
damienmckennaComment #17
japerryDrupal 7 is no longer supported, closing.