How to add a field to POST values in CKeditor upload

后端 未结 6 1906
清歌不尽
清歌不尽 2020-12-31 21:21

I use django and ckeditor to provide wysiwyg taste to TextEdits. I would like to use CKEditor file upload function (in filebrowser / image dialog), but the

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 21:59

    You can register for the dialogDefinition event, and completely rewrite the upload tab, thus:

    CKEDITOR.on('dialogDefinition', function (ev) {
      var dialogName = ev.data.name;
      var dialogDefinition = ev.data.definition;
      if (dialogName == 'image') {
        dialogDefinition.removeContents('Upload');
        dialogDefinition.addContents({
          title: "Upload",
          id: "upload",
          label: "Upload",
          elements: [{
            type: "html",
            html: '
    {%csrf_token%}
    ' }] }); } });

    This is an untested simplification of my real-world version, but hopefully it shows the idea.

    This does not set the URL field in the image dialog, so clicking OK on the dialog will give you an error message. You will need to set that on a successful upload, thus:

    CKEDITOR.dialog.getCurrent().getContentElement('info', 'txtUrl').setValue(theURL);
    

提交回复
热议问题