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. Linux下第一次使用MySQL数据库,设置密码

    在终端下输入:/etc/rc.d/init.d/mysqld status 查看MySQL状态,看看是否运行. 没有运行的话就输入:/etc/rc.d/init.d/mysqld start 这时,就 ...

  2. 动手动脑及java程序之用消息框进行数的运算

        动手动脑     自信成就人生 动手动脑1 ✿仔细阅读示例: EnumTest.java,运行它,分析运行结果? package demo; public class Test { publi ...

  3. Asp.Net - 9.socket(聊天室)

    9.1 Socket相关概念 IP地址 每台联网的电脑都有一个唯一的IP地址. 长度32位,分为四段,每段8位,用十进制数字表示,每段范围 0 ~ 255 特殊IP:127.0.0.1 用户本地网卡测 ...

  4. 微信公众平台中的openid是什么?

    在微信公众平台开发中,会遇到一个叫openid的东东,让我们这些不懂开发的摸不着头脑,开始我也是一头雾水,经过多方面查资料,终于明白是怎么回事了! openid是公众号的普通用户的一个唯一的标识,只针 ...

  5. ShooterGame 学习笔记1 PlayerPawn的两个Mesh的可见性

    GameMode Override 为 ShooterGame_TeamDeathMatch GameMode中设置的Default Pawn Class 为 PlayerPawn , PlayerP ...

  6. 如何学习FPGA?FPGA学习必备的基础知识

    如何学习FPGA?FPGA学习必备的基础知识 时间:2013-08-12 来源:eepw 作者: 关键字:FPGA   基础知识       FPGA已成为现今的技术热点之一,无论学生还是工程师都希望 ...

  7. 19条ANDROID平台设计规范(转)

    1.尺寸以及分辨率: Android的界面尺寸比较流行的有:480*800.720*1280.1080*1920,我们在做设计图的 时候建议是以 480*800的尺寸为标准; 2.界面基本组成元素: ...

  8. 2015腾讯web前端笔试题

      1 请实现,鼠标点击页面中的任意标签,alert该标签的名称.(注意兼容性) 2 请指出一下代码的性能问题,并经行优化. var info="腾讯拍拍网(www.paipai.com)是 ...

  9. Jquery禁止/恢复按钮与文本框代码

    最近,加入了一个小项目,由浩哥带领我们几个人一起开发一个东西.幸运的是,我和胡志婷分到了一组,她可是一个具有丰富经验的牛人,对我也很好,哈哈. --背景 说点正事,最近,我们在进行项目的时候,提到了一 ...

  10. Servlet3.0新特性

    1 Servlet3.0新特性概述 使用要求:MyEclipse10.0或以上版本,发布到Tomcat7.0或以上版本,创建JavaEE6.0应用! Servlete3.0的主要新特性如下三部分: 使 ...