Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor problems updating texarea's value

In my php program I display input forms either regular way on page load or in a dialog box using ajax calls.

There are two methods to create a CKEditor from textarea. Either to use jQuery

$("#textareaid").ckeditor();

or

window["textareaid"] = CKEDITOR.replace("textareaid");

Both methods creates my rich text editor inplace of my textarea in both cases either on page load or after an ajax call. That's fine.

Here starts the problems. In these conditions CKEditor initiates without any console errors, but it never updates textarea value and always sends old value.

1) If I create my textarea on page load and use $("#textareaid").ckeditor();. CKEditor initiates ok without any console errors but on regular form submit, the sent value is empty (old value).

2) If I create my textarea after an ajax call and use window["textareaid"] = CKEDITOR.replace("textareaid"); . Again CKEditor initiates correctly but if I do $("form").serialize() and alert the result I see that textarea value is empty (old value).

I can't create a demo page and upload right now and I know that no one will try to replicate this issue without my codes (at least I wouldn't because I'm so lazy)

I'll prepare a demo page to replicate this issue for you guys but until then I'm asking if someone here faced the same problem and know the reason or found a solution?

Thanks

like image 894
Ergec Avatar asked Dec 21 '22 07:12

Ergec


2 Answers

You should be ok if you call:

 CKEDITOR.instances[your instance].updateElement();

'your instance' in the eaxmple would be simply textareaid since that's what you're using in the CKEDITOR.replace() function

before you serialize the form.

Had the exact same problems a couple of days ago :)

like image 191
Yngve B-Nilsen Avatar answered Dec 30 '22 10:12

Yngve B-Nilsen


I just experienced this same symptom and it seems to be tied to using an id to select the object for the textarea instead of name with jQuery adapter. The reference material on the jQuery adapter does state that when it is a textarea it will automatically send this value back, so it may not validate correctly as a textarea with a jquery $("#myTextarea").ckeditor();

If you want to keep the id selector, an option is to use a hidden field with the final form field name that you send the value to when you submit the form. $("#myHiddenField").val($("#myTextarea").val());

like image 45
Eric P Avatar answered Dec 30 '22 09:12

Eric P