Reputation: 149
I have a Website that allows users to make input and create new content. I always used tinymce for the input fields. after switching to ckeditor today, i noticed, that i ran into the same problems, that i had with tinymce in the beginning:
When submitting the form, the changes made to the content in the editor are not submitted. somehow the ckeditor.getData()-Method seems to return the old value (not the updated one). In some cases it returns the new value. (This only happens when I try to update content, which I loaded into the editor with setData(), not with empty ckeditor-elements)
I really can't figure out why ckeditor does this...
In tinymce this was solved by calling tinyMCE.triggerSave(); before getting the content of the textarea, but i can't find an equivalent for ckeditor, does anyone know how to refresh the content before trying to read it from the editor? because this is starting to drive me crazy...
Upvotes: 1
Views: 2240
Reputation: 29
Having the same issue, after pasting in an item, if I add a space to the end of the text area then it will trigger the update and getData() will return the new correct value.
Otherwise after the paste there is no update made to the getData();
editor.updateElement() // did nothing
Upvotes: 0
Reputation: 22023
If CKEditor replaces a <textarea>
in a <form>
it adds a listener to the form's onsubmit
event, so when the form is being submitted the editor.updateElement()
method is called in order to update value of the <textarea>
.
I've never heard about case when submitting the form would not trigger this mechanism, but if for some reasons it doesn't work for you then you can:
editor.updateElement()
method manually,editor.getData()
method to get the data directly and use it in an XHR request if you do such (that would explain why onsubmit
is not executed).You can read more in:
Upvotes: 2
Reputation: 149
Actually this here seems to fix it (at least in 99% of cases) http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-updateElement
Maybe someone knows a better answer...
Upvotes: 2