Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you have a plain text field in Drupal that uses the wysiwyg (ckeditor) widget, no text will appear and when you attempt to save the text entered in ckeditor will not save.
This is because of how CKEDITOR.replace() works. it will use the innerHTML() of any DOM element, http://docs.ckeditor.com/#!/api/CKEDITOR-method-replace. To get around this it might be possible to clone the original textfield before calling CKEDITOR.replace, replacing the textfield with a textarea. Then when the CKEDITOR instance is destroyed, the original textfield may replace the textarea that was created.
Comments
Comment #1
svajlenka CreditAttribution: svajlenka commentedThis also affects 2.x-dev, I'm also supplying a patch made against dev.
Comment #2
svajlenka CreditAttribution: svajlenka commentedComment #3
TwoDThanks for the patch!
I've been meaning to write something like this for a long time, see #971632: CKeditor breaks on text field (not on field type Long Text) but I've just not gotten around to it.
I see one potential problem with this specific implementation though. What happens if another script has references to the original field or attaches events to that element? Since it's being cloned and replaced, I'm assuming those events would get lost.
What if we instead just hide the original field and create the new textarea next to it, then sync contents to the textfield after detaching?
That'll keep all references/events intact (and things like
onchange
should trigger when the contents do change).Do we need to consider newlines? A quick experiment seems to indicate that newlines will simply be ignored when put into a textfield.
Maybe we should make it so that the editor implementations do not have to worry about this at all and always see textareas by moving this into wysiwyg.js (maybe into
Drupal.wysiwyg[De|At]tach()
). That would take care of FCKeditor as well (yes, I think some are still using it.) I don't remember if all other supported editors work with textfields. If they do, maybe just copy this change to FCKEditor...Comment #4
jojonaloha CreditAttribution: jojonaloha at Metal Toad commentedThe patch in #1 fixed the issue for me using Wysiwyg 7.x-2.2.
Comment #5
sadashiv CreditAttribution: sadashiv commented#1 worked for me.
Thanks,
Sadashiv.
Comment #6
blake.thompson CreditAttribution: blake.thompson at Forum One commentedThe patch in #1 kept the data when changing text formats but didn't save the changes when the input was a textarea. Updated patch fixed that issue for me.
Comment #7
VeniaminLopatin CreditAttribution: VeniaminLopatin commentedThe problem is still exists in 7.x-2.3 version.
Is here any solution for that?
Comment #8
Stefan Lehmann CreditAttribution: Stefan Lehmann at Sparks Interactive commentedI just reapplied the patch from #7 to the 7.x-2.3 version and it still seems to work, when put into the correct place. Might fix the issue for people until somebody comes around with a real fix.
Comment #9
JamesOakleyI'd gladly submit an amended patch, but I don't understand how this particular module works. So I'll report the problem and someone else can comment on how easy it would be to fix.
The patch at #7 fixes the problem on a test site I tried it on. However, the ckeditor text area that was created was collapsed into minimum height, so that (even though a text field had content in it), it still looked empty when the rich text editor was enabled. I therefore almost thought the patch hadn't worked, until I dragged the resize handle down, then I could see the content in the editor.
Is there any way to set the starting height for the rich text editor to be one line high?
Comment #10
TwoDI'm not very happy about replacing the original field completely because we may destroy event handlers attached to it, and we'll have no way to add them back.
I think if we on attach instead hide the original field, insert a textarea with some unique id, and then attach the editor to that.
On detach we detach the editor, sync the contents to the original field, and then remove the textarea.
One issue is that the editor will need to attach to a different id than what the client has been passed settings for so that part will be out of sync. "Outwards" will also have to give the appearance of attaching to the original textfield using the original id, or 3rd party code will not find the correct editor instance.
Comment #11
Stefan Lehmann CreditAttribution: Stefan Lehmann at Sparks Interactive commented@JamesOakley:
You could probably try to add a style attribute on the textarea with a minimum height value or so ..
@TwoD:
Yeah I thought so too. However it's an interim solution for people who have clients strangling their necks. :-) Before that issue I didn't even know that one can assign a WYSIWYG to a normal textfield.
Comment #12
sgalindo2388 CreditAttribution: sgalindo2388 commentedRemoved '.txt' from file name to be able to apply the patch using drush make.
Comment #13
Sardis CreditAttribution: Sardis at Drupalway, Drupal Ukraine Community for Drupal Ukraine Community, Drupalway commentedWhat should one do if he uses 4.6.2.20af917 version? I've applied the patch, but it doesn't do any good.
Much appreciate the help.
Comment #14
dlriley CreditAttribution: dlriley commentedI've made another patch from #12 that works with CKEditor 4.9.2
Comment #15
wesruv CreditAttribution: wesruv at Lullabot commentedUsing "4.6.2" #14 works great for me!
Comment #16
nplowman CreditAttribution: nplowman at FFW commentedAttaching a re-rolled patch that will work with the latest version (7.x-2.5).
Comment #17
gsquirrelWorked well for me
Comment #18
steinmb CreditAttribution: steinmb as a volunteer and at University Of Bergen commentedCannot find comment from the maintainer in #10 addressed in the latest patches, back to NW.