The following error is triggered, when trying to rerun Drupal.attachBehaviors on a dynamically loaded node edit form (and possibly other dynamic loaded forms).
uncaught exception: [Exception... "'[CKEDITOR.editor] The instance "edit-field-postit-da-0-value" already exists.' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: chrome://firebug/content/spy.js :: callPageHandler :: line 744" data: no]
Scenario
1. The page is loaded, with a customized node_form, for the user to create a new node.
2. The user clicks on another subject, we get (AJAX) a new form for creation, and replace the old form (by simply setting the HTML of it's parent).
3. Now the Drupal.attachBehaviors([NEW CONTENT]) is called to activate the CKEditor and other behaviors. And this is when the error is triggered.
The error happens because the node form has the same field ids, so the CKEDITOR.instances already have an instance of that particular id.
To fix the error we need to check if an instance already exists (and remove it if it does), before the new instance is created (included a patch).
Comment | File | Size | Author |
---|---|---|---|
#1 | wysiwyg-ckeditor-instanceexists-1223080-1.patch | 508 bytes | sven.lauer |
wysiwyg-ckeditor-instanceexists.patch | 510 bytes | Birk |
Comments
Comment #1
sven.lauer CreditAttribution: sven.lauer commentedRaising priority to major, as this completely breaks multi-value instances with the editor (on hitting the "add another value" button, the editor disappears on the existing elements (which is completely gone, not even the div remains) and does not get attached to the new items.
Reviewed the original patch (well ... it's a three-liner, but it does the right thing) and tested it. Solves the problem. There is a minor white-space issue, so I am re-rolling the patch to fix that. Applies against the git master branch.
Comment #2
sven.lauer CreditAttribution: sven.lauer commentedComment #3
TwoDWould't the patch in #1155678: Implement Drupal.behaviors.attachWysiwyg.detach do the same thing, but for all editors?
Comment #4
sunRight. Thanks for attempting to provide a patch though, @sven.lauer.
Comment #5
sven.lauer CreditAttribution: sven.lauer commentedMy bad, should have checked if this is a more general problem first.
Comment #6
nesta_ CreditAttribution: nesta_ commentedComment #7
husumiao-1 CreditAttribution: husumiao-1 commentedThank you so much, Birk.
So pretty solutions.
Comment #8
guignonv CreditAttribution: guignonv commentedHi!
I'd like to point out that the patch at #3 was for the 7.x, not the 6.x.
This issue is pretty old and doesn't seem to have been fixed in current release of wysiwyg (6.x-2.4).
Wouldn't it be a good idea to include patch #1 in the 6.x branch since I also tested it and it works just fine?
Comment #9
TwoD@guignonv Drupal 6 does not have detach() methods for behaviors, so that patch can not be ported.
There is a workaround for D6, but it involves a couple of more modules and libraries which together provide similar functionality: Wysiwyg CCK integration module.