Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField, {
  /**
    * @cfg {String} buttonText The button text to display on the upload button (defaults to
    * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
    * value will be used instead if available.
   */
  buttonText : '文件上传',
  /**
    * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
    * text field (defaults to false). If true, all inherited TextField members will still be available.
   */
  buttonOnly : false,
  /**
    * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
    * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
   */
  buttonOffset : 3,
     /**
    * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
   */

  // private
  readOnly : true,

  /**
    * @hide
    * @method autoSize
    */
  autoSize : Ext.emptyFn,

  // private
  initComponent : function() {

            this.renderTo = this.applyTo || this.renderTo;
            delete this.applyTo;
            var oldel = Ext.fly(this.renderTo);

           if (oldel&&oldel.dom.type && oldel.dom.type == "file") {

        var id = oldel.dom.id;

       this.width = oldel.getWidth() || 200;
       Ext.apply(this, this.getConfig(oldel.dom));
       var parent = oldel.parent();
       oldel.remove();
                parent.dom.innerHTML='<div id="'+this.id + '-renderto'+'"></div>';
       this.renderTo = this.id + '-renderto';

          }

     Ext.ux.form.FileUploadField.superclass.initComponent.call(this          this.addEvents(          /**

            * @event fileselected
            * Fires when the underlying file input field's value has changed from the user
            * selecting a new file from the system file selection dialog.
            * @param {XY.form.FileUploadField} this
            * @param {String} value The file value returned by the underlying file input field
           */
           'fileselected');
         },
         getConfig : function(dom) {
           return {
         // applyTo : dom.id,
        icoCls : dom.className
        //id : dom.id,
        //tabIndex : dom.tabIndex
       }
        },
        // private
    onRender : function(ct, position) {
        Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct,
                                position);

         this.wrap = this.el.wrap({
            cls : 'x-form-field-wrap x-form-file-wrap'
                  });  
                  this.el.addClass('x-form-file-text');
         this.el.dom.removeAttribute('name');
         this.createFileInput();

        var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
           text : this.buttonText
        });
        this.button = new Ext.Button(Ext.apply(btnCfg, {
           renderTo : this.wrap,
           cls : 'x-form-file-btn'
                + (btnCfg.iconCls ? ' x-btn-icon' : '')
        }));

        if (this.buttonOnly) {
           this.el.hide();
             this.wrap.setWidth(this.button.getEl().getWidth());
        }

        this.bindListeners();
           this.resizeEl = this.positionEl = this.wrap;
        },

        bindListeners : function() {
           this.fileInput.on({
                 scope : this,
                 mouseenter : function() {
                 this.button.addClass(['x-btn-over',
                 'x-btn-focus'])
        },
        mouseleave : function() {
           this.button.removeClass(['x-btn-over',
                 'x-btn-focus', 'x-btn-click'])
        },
        mousedown : function() {
           this.button.addClass('x-btn-click')
        },
        mouseup : function() {
           this.button.removeClass(['x-btn-over',
                'x-btn-focus', 'x-btn-click'])
        },
        change : function() {
           var v = this.fileInput.dom.value;
           this.setValue(v);
           this.fireEvent('fileselected', this, v);
        }
         });
    },

    createFileInput : function() {
       this.fileInput = this.wrap.createChild({
            id : this.getFileInputId(),
            name : this.name || this.getId(),
            cls : 'x-form-file',
            tag : 'input',
            type : 'file',
            size : 1
       });
    },

    reset : function() {
       this.fileInput.remove();
       this.createFileInput();
       this.bindListeners();
    Ext.ux.form.FileUploadField.superclass.reset.call(this);
    },

    // private
    getFileInputId : function() {
       return this.id + '-file';
    },

    // private
    onResize : function(w, h) {
    Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);

    this.wrap.setWidth(w);

    if (!this.buttonOnly) {
           var w = this.wrap.getWidth()
           - this.button.getEl().getWidth()
           - this.buttonOffset;
          this.el.setWidth(w);
       }
   },

// private
   onDestroy : function() {
   Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
   Ext.destroy(this.fileInput, this.button, this.wrap);
        },

   onDisable : function() {
   Ext.ux.form.FileUploadField.superclass.onDisable.call(this);
   this.doDisable(true);
   },

onEnable : function() {
        Ext.ux.form.FileUploadField.superclass.onEnable.call(this);
        this.doDisable(false);

},

   // private
      doDisable : function(disabled) {
             this.fileInput.dom.disabled = disabled;
        this.button.setDisabled(disabled);
  },

  // private
  preFocus : Ext.emptyFn,

  // private
  alignErrorIcon : function() {
  this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  }

});

Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);

jsp页面的代码如下:
      <input id="attachFileInfo" name="attachFileInfo" type="file"/>
      注:Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
      fileuploadfield:为input中的id;

Ext.ux -----> XY

ExtJs文件上传(Ext.ux.form.FileUploadField)的更多相关文章

  1. 自定义ExtJS文件上传

    日常工作中,一般文件上传都是跟随表单一起提交的,但是遇到form表单中有许多地方有文件上传时这种方式却不是很适用,以下是我工作中用的文件上传方式: { xtype: 'fileuploadfield' ...

  2. struts2+extjs文件上传完整实现(攻克了上传中的各种问题)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/shanhuhau/article/details/28617999 首先须要引入上传控件 <s ...

  3. PHP+ExtJS 文件上传示例

    xtJS 4 有一个非常方便的文件上传组件,可以用来将文件上传到服务器.本文PHP教程UncleToo将介绍使用PHP和ExtJS实现文件上传功能. 首先,创建文件上传组件Ext.form.Panel ...

  4. Extjs文件上传问题总结

    本来文件上传是一个简单而常用的功能,但是,由于刚刚接触extjs,对extjs中的控件及其使用方法并不熟悉,导致本来一个很快就可以搞定的文件上传问题,弄了将近两天的时间.现将问题及解决办法发出来,供有 ...

  5. extjs文件上传

    EXT学习教程:http://www.cnblogs.com/iamlilinfeng/category/385121.html Ext文件上传: 例子用到的jar:   1.upload.js /* ...

  6. Extjs 文件上传

    function fromExcel(){ var dxjgdm_sel = Ext.get("dxjgdm").getValue(); var dxjglx_sel = Ext. ...

  7. js文件上传原理(form表单 ,FormData + XHR2 + FileReader + canvas)

    目录 form表单上传 FormData + XHR2 + FileReader + canvas 无刷新本地预览压缩上传实例 目前实现上传的方式 浏览器小于等于IE9(低版本浏览器)使用下面的方式实 ...

  8. Spring MVC 文件上传简单示例(form、ajax方式 )

    1.Form Upload SpringMVC 中,文件的上传是通过 MultipartResolver 实现的,所以要实现上传,只要注册相应的 MultipartResolver 即可. Multi ...

  9. 文件上传时jquery.form.js中提示form.submit SCRIPT5: 拒绝访问

    利用其它控件触发file的click事件来选择文件后,使用jquery.form.js中的submit方法提交时IE报错:form.submit SCRIPT5: 拒绝访问,其它浏览器正常, < ...

随机推荐

  1. HTTPS的一些疑问解答

    PHP写的网站怎么用https访问,具体要怎样 这跟用什么语言写的网站没有关系,可以去申请个快速的SSL证书,一年也就几十块. 开启apache server的ssl,自己做个免费的ssl证书或者去申 ...

  2. Shell编程基础教程2--变量和运算符

    2.变量和运算符 2.1.变量的类型 本地变量:环境变量:变量替换(显示变量):位置变量:标准变量:特殊变量: 2.2.本地变量 本地变量在用户现在的shell生命周期的脚本中使用 在命令行, LOC ...

  3. Pyqt 时时CPU使用情况

    借鉴代码来自:https://github.com/hgoldfish/quickpanel 实现代码: # -*- coding:utf-8 -*- from __future__ import p ...

  4. 【数据结构】建立和平衡AVL二叉树

    一步一步写平衡二叉树(AVL树) 原文地址:http://www.cppblog.com/cxiaojia/archive/2012/08/20/187776.html 我添加了一些内容,以充实整个算 ...

  5. android 入门- 词汇

    final Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes();获得自定 ...

  6. phpcms_v9 多图字段 内容页,首页,分页自定义字段调用

    phpcms_v9 多图字段 内容页,首页,分页自定义字段调用 说明:自定义多图字段名 shigongtu 1 内容页调用 {loop $shigongtu $r}      <img src= ...

  7. [Tools] 使用XP远程登录Win8系统

    [背景] 完成最基本的设置后,发现xp依然不能远程访问win8桌面,搜索后发现需要进一步设置   [开工] 按照参考资料进行设置,下面的参考资料已经写的很详细了,只是参考资料2中的文件名: redss ...

  8. 提供给Android和iOS开发人员的UWP移植向导

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:前几天微软发布了一个针对Android和iOS开发人员理解Windows Apps概念 ...

  9. web开发的步骤

    前端知道是浏览器呈现的部分,相对于前端,后台你可以理解为服务器端专门处理.读取.存储数据库数据的部分. 因为网站是基于B\S架构,即浏览器---服务端架构,就程序来讲,可笼统划分为前端程序和服务器端程 ...

  10. 函数调用关于从Ring3转到Ring0 ESP堆栈变化

    在ring0堆栈获取ring3堆栈方式 第一种方式 [esp+4] == [esp+参数个数*4+4] 如果这里不相等就需要用第二种方式 [[esp+参数个数*4+8]] 这里面的值就是Ring3的堆 ...