Hello,
In a given node form including a textarea with a ckeditor, and a file upload widget (or any other widget using AJAX calls), triggering the AJAX call (e.g. by uploading the image, or clicking "Add another item" on a multi-delta field) will remove and re-add again ckeditor.
In a node form with many widgets using AJAX, it can get quit annoying and slow down the user (on slower computers).
This behavior is triggered due to the following bit of code in misc/ajax.js which detach behaviors:
Drupal.ajax.prototype.beforeSerialize = function (element, options) {
// Allow detaching behaviors to update field values before collecting them.
// This is only needed when field values are added to the POST data, so only
// when there is a form such that this.form.ajaxSubmit() is used instead of
// $.ajax(). When there is no form and $.ajax() is used, beforeSerialize()
// isn't called, but don't rely on that: explicitly check this.form.
if (this.form) {
var settings = this.settings || Drupal.settings;
Drupal.detachBehaviors(this.form, settings, 'serialize');
}
Which will call the ckeditor behavior detach function, which remove the ckeditor. And then it's added back just after.
Since the main job of the ckeditor detach function is to update the textarea input for form submission, I'm not sure why the ckeditor is removed in top of that. It could stay.
Attaching a patch just below.
Comment | File | Size | Author |
---|---|---|---|
#4 | 0001-1491210-by-michal_cksource-Ckeditor-gets-disabled-en.patch | 1.42 KB | mkesicki |
#3 | ckeditor-disable-enable-on-ajax-2-1491210.patch | 953 bytes | ndeschildre |
#1 | ckeditor-disable-enable-on-ajax-1491210.patch | 565 bytes | ndeschildre |
Comments
Comment #1
ndeschildre CreditAttribution: ndeschildre commentedPatch attached. The textarea is still updated.
But I'm pretty sure I'm missing why the actual ckeditor is removed on detach.
Comment #2
mkesicki CreditAttribution: mkesicki commented@ndeschildre thank you for patch.
We will check this as soon as possible.
Comment #3
ndeschildre CreditAttribution: ndeschildre commentedOk I updated the patch to be more 'smart', as I discovered the detach 'trigger' parameter. So now it will only unload ckeditor on detach with the 'unload'/'move' event, but no longer on the 'serialize' event (which is called in the use case I'm trying to solve).
Comment #4
mkesicki CreditAttribution: mkesicki commentedI add patch that can be added to repository.
Thank you @ndeschildre , well done.
Maybe some other will test this ?
Comment #5
dczepierga CreditAttribution: dczepierga commentedPatch commited to GIT (diff)
Greetings
Comment #6
dczepierga CreditAttribution: dczepierga commentedComment #7
ndeschildre CreditAttribution: ndeschildre commentedThanks!