While debugging a reopened/repurposed issue in the Wysiwyg module - see #1757684-25: Ajax error on Add another item (#25 and onwards) - I noticed that Drupal (7) will automatically call Drupal.attachBehaviors(this.form, settings)
for any form submitted through AJAX, such as a node edit form in a CTools Modal. The problem is, the modal is closed and the form has been removed from the document, only the reference to it in the AJAX instance is keeping it around.
This can cause problems for behaviors trying to work with the DOM elements in the form, since they can't reach outside the form, and elements in the form can't be reached from anywhere else in the document. On top of that, since closing the modal does not generate any settings commands, Drupal defaults to passing in all of Drupal.settings
for just the form element. Reality gets out of sync with the script states as the form element is whisked away into nothingness as soon as the AJAX operation is over.
How about removing the reference keeping the form around and work around Core getting us into this mess?
The attached patch does this quite easily, but I'll also post report the problem in Core, so that should show up as a related issue soon.
Btw, I'm hesitant to call this a bug in CTools, since I think Core shouldn't behave this way in the first place, but I wasn't sure what to call it.
Comment | File | Size | Author |
---|---|---|---|
#5 | ctools-prevent_core_from_attaching_behaviors-2215821-5.patch | 569 bytes | Andrew Answer |
ctools-remove-modal-form-reference.patch | 587 bytes | TwoD |
Comments
Comment #1
tim.plunkettIs this superseded by #2215857: Behaviors get attached to removed forms?
Comment #2
TwoDIf #2215857: Behaviors get attached to removed forms gets in, this patch isn't technically needed anymore, but having it anyway wouldn't hurt since there is still a slight risk some other snippet of code in another module does something similar when the form appears to still be there. It does make it a lot more obvious from an external POV that the form in the modal was just obliterated.
Comment #4
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe patch to modal.js does not apply to the latest ctools 7.x-1.x-dev so needs a reroll.
Comment #5
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPatch rerolled.