Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291082

Drupal.editors.ckeditor.onChange() misses changes made by last keypress — leads to data loss

$
0
0

Drupal.editors.ckeditor.onChange() looks like this:

  onChange: function (element, callback) {
    var editor = CKEDITOR.dom.element.get(element).getEditor();
    if (editor) {
      var changed = function () {
        callback(editor.getData());
      };
      // @todo Make this more elegant once http://dev.ckeditor.com/ticket/9794
      // is fixed.
      editor.on('key', changed);
      editor.on('paste', changed);
      editor.on('afterCommandExec', changed);
    }
    return !!editor;
  },

As you can see, we're blocked on http://dev.ckeditor.com/ticket/9794 to get nicer and more reliable code there.

Sadly, editor.getData() does not yet contain the changes made by the latest keypress!

E.g.: the value is fooba. You type an 'r' at the end of this, now the visible value is foboar. But editor.getData() will still return fooba!

The temporary solution I found was to change the changed callback to wrap the call to editor.getData() in a window.setTimeout… not very nice, but it works for now:

      var changed = function () {
        window.setTimeout(function () {
          callback(editor.getdata());
        }, 0);
      };

Viewing all articles
Browse latest Browse all 291082

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>