Hi @all,

as stated here #1155678: Implement Drupal.behaviors.attachWysiwyg.detach, this issue normally should be fixed already, but see the last comment on that issue and for me the same problems occure, when having a WYSIWYG editor (in my case latest CKEditor 4.2.1) as part of a field collection item.

I get the following JS error when trying to add a new field collection item via "Add another item" button:

TypeError: Argument 1 of Node.appendChild is not an object. (jquery.js?v=1.5.2 (Line 5636)

After that, the editor in my first field collection item is empty and all its buttons are grayed out.

Does anybody have an idea, what's happening? If you need further information, please let me know.

Thanx in advance & cheers

hctom

Comments

TwoD’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not getting that error even when using format enabled unlimited-value fields inside an unlimited-value field_collection along with other format-enabled unlimited-value fields outside the collection. (Embedded widgets.)

I tested with Wysiwyg-7.x-2.x, Field collection 7.x-1.0-beta5 and CKEditor's latest development variant (small version-detection hack needed for that, but the Full variant is detected properly) in Chrome.

The error triggered by previously not implementing Drupal.behaviors.attachWysiwyg.detach was caused by lingering editor instances after the textareas they belonged to had been removed, and then re-created, because of the way AJAX events update the document.

The error you're getting is being thrown somewhere inside jQuery, most likely because it's being told to insert a node which no longer exists. The Field collection module does not appear to add or modify any of the scripts related to this process, or anything related to how Wysiwyg works. So, perhaps there are certain cases where the markup generated by the module on the server side isn't what the standard Drupal scripts expect to insert on the client side. That's just a guess though.

Which admin-theme are you using? Have you tried different ones?
Which fields are you using on the content type on which this happens?
Are you using any other modules which add scripts or otherwise modify the node edit forms?
Can you get a backtrace of that error and see if any Wysiwyg-related functions are somewhere in the stack? Look especially for the attach() and detach() methods found in wysiwyg/editors/js/ckeditor-3.0.js as well as the libraries/ckeditor/ckeditor.js file itself, and see if they're calling something which eventually boils down to that error being thrown.

hctom’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Hi @all,

I finally found the error: The damn Media module (7.x-2.0-alpha2) has the following method in js/media.filter.js:

create_element: function (html, info) {
  if ($('<div></div>').append(html).text().length === html.length) {
    // Element is not an html tag. Surround it in a span element
    // so we can pass the file attributes.
    html = '<span>' + html + '</span>';
  }
  // ... even more code to come ...
  return element;
},

Unfortunately, this function sometimes receives an array as html argument, which causes this error...

So for all others encountering this error, add the following to the method definition:

if (Object.prototype.toString.call(html) == '[object Array]') {
  html = html.shift();
}

Cheers

hctom

k.minkov’s picture

Issue summary: View changes

What I noticed is that this issue happens(at least in my case) only when in the CKEditor in the first field collection there is an image form media module. This fix works perfectly.

Bogdan1988’s picture

Thank you, hctom. We should create issue for media module to fix it. Or we have already created it?

malc0mn’s picture

Just to confirm that #2 fixes the field_collection issue perfectly!

But who will fix this one properly in the end?