The lack of a detach method on the WYSIWYG Drupal.behaviors object causes WYSIWYG in multi value fields to clear the value of the WYSIWYGs when "Add another item" is clicked.

I've attached a patch that detaches the WYSIWYG so that it's value can be passed to the AJAX callback and the form rebuilt with the value kept.

Comments

lukus’s picture

I applied this manually to version 7.x-2.1.

Seems to work perfectly.

Solved my issue discussed here: http://drupal.org/node/1238464

Would love it if this could be integrated into the main release.

Jody Lynn’s picture

StatusFileSize
new610 bytes

I also needed a detach function, and just came up with one that's working for me (I think the above looks better, but my version is attached).

My issue is that I'm using wysiwyg (ckeditor) within an ajax multistep form. When I hit the 'next' button to go to my next step in the form, the text in the wysiwyg would be lost as the containing form was not conventionally submitted to trigger Drupal.wysiwygDetach.

Adding a detach function fixed it.

pavlosdan’s picture

Patch at #1 worked for me as well. Had the same issue described in the Issue Summary

bleen18’s picture

subscribing

tigerfinch’s picture

Patch #1 works great for me, had the same issue. Applied to 7.x-2.1.

TwoD’s picture

Please clarify, #1 has no patch. Did you mean the patch in the original post, or the one in #2?

tigerfinch’s picture

Apologies, I meant the original post.

ParisLiakos’s picture

Status:Needs review» Reviewed & tested by the community

Thank you!!
james.elliott's patch works for me as well with both CKeditor and TinyMCE (had to clear cache to take effect)

RaF7’s picture

subscribe

animelion’s picture

OP's post is the only way I could get field collections to work with "WYSIWYG: CKEditor". Thanks a million!

danielnolde’s picture

0001-Fix-multi-value-fields-with-WYSIWYG.patch works like a charm and solves the problem of wysiwyg fault on multiple text area fields.
When does this get commited into wysiwyg api's code base??

g.oechsler’s picture

0001-Fix-multi-value-fields-with-WYSIWYG.patch works fine here as well. Thanks a lot!

sun’s picture

Version:7.x-2.0» 7.x-2.x-dev
Status:Reviewed & tested by the community» Fixed
StatusFileSize
new1.04 KB
+++ b/wysiwyg.js
@@ -80,6 +80,13 @@ Drupal.behaviors.attachWysiwyg = {
+    $('.wysiwyg-processed', context).each(function (index, element) {
+      $(element).removeClass('wysiwyg-processed');

We have .removeOnce() for that. :)

Thanks for reporting, reviewing, and testing! Committed attached patch to 7.x-2.x.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

phpconnect’s picture

Status:Closed (fixed)» Active

I have still getting this issue and i have latest version of wysiwyg 7.x-2.1.
I am using TinyMCE 3.5.6 version for wysiwyg.
I check the ajax request still editor value is going empty.

TwoD’s picture

Status:Active» Closed (fixed)

There has not been an official release since this patch was committed. You need Wysiwyg 7.x-2.x-dev until we have another release (7.x-2.2).

MattBondi’s picture

Thanks for this! Patch at #13 worked a charm.

TwoD’s picture

@MattBondi, you should no longer need the patch since it's now part of 7.x-2.2.

skalfyfan’s picture

Can this patch be applied to the latest WYSIWYG 6.x tree as well?

The problem still persists in the 6.x version.

skalfyfan’s picture

Actually can see now that they are quite different and I gather that no patch for 6.x is forthcoming. Ohwell.

Mschudders’s picture

Well I am just posting my code here that fixes the issue for me without messing in Wyswig.

Just put this in a separate JS file in your theme or whatever (Make sure to change to Jquery ID 's :-) )

/**
* Bug fix bug in Wysiwyg module that will not get backported to D6.
*/
jQuery(document).ajaxSend(function(event, jqxhr, settings) {
  if ( settings.url.indexOf('content_multigroup/js_add_more/article/group_article_paragraph') >= 0 ) {
    // Getting my values.
    var htmlOfTextAreas = new Array();
    for (var j = 0; j < 25; j++) {
      if (jQuery('#edit-group-article-paragraph-' + j + '-field-article-paragraph-text-value_ifr').length > 0) {
        htmlOfTextAreas.push(jQuery('#edit-group-article-paragraph-' + j + '-field-article-paragraph-text-value_ifr').contents().find("body").html());
      }
      else {
        // Skip the loop
        break;
      }
    }

    // group_article_paragraph[0][field_article_paragraph_text][value]
    var dataSettings = settings.data;
    // Splitting the string to an array.
    var htmlArray = dataSettings.split("&");
    var counterHtmlArray = 0;

    for (var i = 0; i < htmlArray.length; i++) {
      // Split the key value pair so I can check.
      var keyValue = htmlArray[i].split("=");
      if (keyValue[0].indexOf("field_article_paragraph_text") !== -1 && keyValue[0].indexOf("value") !== -1) {

        keyValue.splice(1, 1);
        keyValue.push(htmlOfTextAreas[counterHtmlArray]);
        var noSplittedArrayBackToString = keyValue.join("=");
        htmlArray[i] = noSplittedArrayBackToString;

        counterHtmlArray++;
      }
    }
    // Passing back to new settings array.
    var noSplittedHtmlArray = htmlArray.join("&");
    settings.data = noSplittedHtmlArray;
  }
});

hope this helps someone

lakes’s picture

@TwoD:I have 7.x 2.2 installed and I get the same error. With WYSIWYG and TinyMCE. I am creating my fields through the latest version of Field collections. Any ideas what the problem could be?

artem.kolotilkin’s picture

I have the same issue with Wysiwyg 7.x-2.2. Can we reopen this issue and look further?

hctom’s picture

@lakes and @artem.kolotilkin: Do you have the media module installed? If so, check #2107271: Method in media.filter.js receives different types of arguments as this was the problem on my side... But unfortunately my issue has been "ignored" by the media guys until now :(

Cheers

hctom

4x3’s picture

Issue summary:View changes

Also experiencing the same issue with latest dev and patches included. CKEditor will not render with Field Collections on same edit page.
Drupal core 7.26
wysiwyg 7.x-2.2+26-dev (2014-Feb-07)
field_collection 7.x-1.0-beta5+8-dev (2013-Oct-10)

RaulMuroc’s picture

HAving the same issue with latest 7.x-2.2 version.

If I fill the Field collection field with Plain text or Full Html/Filtered html without WYSIWYG it works nice. But once I active WYSIWYG it justt doesn't save/show the content.

So looks is not 100% fixed :S

RaulMuroc’s picture

OK I have discovered that:

1) Create a Field Collection
The bug persists.

1.1) Even more. IF you copy/past a value in the field (in edit mode) or write it manually nothing shows at all but yes it is created as you see when save. The next time we edit it follows the next 2) point.

2) Edit an existing Field Collection
It works as expected.

Hopefully this will drive us to a solution.

Dentorat’s picture

I've also encountered this bug with 7.x-2.2. I upgraded to the dev release and I'm still having the issue.

RaulMuroc’s picture

Status:Closed (fixed)» Active

People report that this problem still exists.

Dhanendran’s picture

Is this issue fixed?

My Scenario:

1. Create field collection field.
2. Add some text in it and add audio/video/document file through media browser.
3. Now click "Add another item"

That's it, text will remain same but the media will be gone.