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).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sven.lauer’s picture

Title: [CKEDITOR.editor] The instance INSTANCE_NAME already exists. » [CKEDITOR.editor] Editor disappears on multi-value field / The instance INSTANCE_NAME already exists.
Priority: Minor » Major
FileSize
508 bytes

Raising 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.

sven.lauer’s picture

Status: Needs review » Reviewed & tested by the community
TwoD’s picture

Would't the patch in #1155678: Implement Drupal.behaviors.attachWysiwyg.detach do the same thing, but for all editors?

sun’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

Right. Thanks for attempting to provide a patch though, @sven.lauer.

sven.lauer’s picture

My bad, should have checked if this is a more general problem first.

nesta_’s picture

Version: 7.x-2.1 » 6.x-2.4
husumiao-1’s picture

Thank you so much, Birk.
So pretty solutions.

guignonv’s picture

Assigned: Birk » Unassigned
Status: Closed (duplicate) » Reviewed & tested by the community

Hi!
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?

TwoD’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

@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.