具有文件输入控制类型的Tinymce弹出窗口

时间:2017-09-14 14:21:47

标签: javascript tinymce-4

在我的自定义tinyme插件上,我想渲染一个带有2个标签的窗口:

  • 一个有网址输入
  • 一个上传文件

完成这项工作的代码是:

tinymce.PluginManager.add('upload', function(ed, url){
        ed.addCommand('initUpload', function(){
          //Do stuff 
        });

        //Register a button that open a window
        ed.addButton('upload', {
          title: 'Upload Files into the editor',
          // cmd: 'initUpload',
          text: '',
          icon:'upload-icon',
          onClick: function(){
            ed.windowManager.open({
              title:'Insert a File',
              bodyType:'tabpanel',
              body:[
                {
                  title: "From file into your computer",
                  type:"textbox",//Thing That I need to change with file input
                  label:"File"
                },
                {
                  title: "From Url",
                  type:"textbox",
                  label:"Url"
                },
              ],
              onsubmit: function(e) {
               //do Stuff
              }
            })
          }
        });
      });

我试图替换:

{
   title: "From file into your computer",
   type:"textbox",//Thing That I need to change with file input
   label:"File"
 },

使用:

{
   title: "From file into your computer",
   type:"file",//Thing That I need to change with file input
   label:"File"
 },

但出于某种原因,我得到了:

  

错误:无法按类型找到控件:file

那么如何将文件控件类型设置为可以渲染的弹出窗口?

1 个答案:

答案 0 :(得分:2)

Add an input element of type=file in tinymce container所示,您只需使用将子类型文件放入选项卡配置即可。

换句话说,替换:

{
   title: "From file into your computer",
   type:"textbox",//Thing That I need to change with file input
   label:"File"
 },

使用:

{
   title: "From file into your computer",
   type:"textbox",
   subtype:"file"
   label:"File"
 },

另请注意,您需要提供onchange回调设置才能获取文件内容。