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. 直接放个DB2 SQL STATEMENT大全好了!

    SQL statements   This topic contains tables that list the SQL statements classified by type. SQL sch ...

  2. Hadoop CDH5 集群管理

    Hadoop 是一个开源项目,所以很多公司在这个基础进行商业化,Cloudera 对 Hadoop做了相应的改变.Cloudera 公司的发行版,我们将该版本称为 CDH(Cloudera Distr ...

  3. Android -- Looper、Handler、MessageQueue等类之间关系的序列图

    原文:Android源码解析之(二)-->异步消息机制 通过阅读文章及其中提到的一些参考文章,模模糊糊的理解了Android的异步消息机制.为了能够进行消化吸收,决定把各类之间的交互通过图的形式 ...

  4. WebService – 3.后台调用WebService,根级别上的数据无效

    1.因为我的webservice返回的是json, 2.ajax传递跨域不安全, 3.contentType: "application/json; charset=utf-8", ...

  5. ASP.NET MVC使用Bundle来打包压缩js和css

    Bundle它是用来将js和css进行压缩(多个文件可以打包成一个文件),并且可以区分调试和非调试,在调试时不进行压缩,以原始方式显示出来,以方便查找问题. 1.BundleConfig配置Bundl ...

  6. HDU4288 Coder(线段树)

    注意添加到集合中的数是升序的,先将数据读入,再离散化. sum[rt][i]表示此节点的区域位置对5取模为i的数的和,删除一个数则右边的数循环左移一位,添加一个数则右边数循环右移一位,相当于循环左移4 ...

  7. mysql 查询优化规则

    .请不要在SELECT中使用DISTINCT: #会用到临时表 .尽可能不要SELECT *,而应该查询需要用到的指定几个字段: .不要对两个大表进行联合,无论是内联或外联.对于需要对两个或多个表进行 ...

  8. Matlab中如何将(自定义)函数作为参数传递给另一个函数

    假如我们编写了一个积分通用程序,想使它更具有通用性,那么可以把被积函数也作为一个参数.在c/c++中,可以使用函数指针来实现上边的功能,在matlab中如何实现呢?使用函数句柄--这时类似于函数指针的 ...

  9. Android开发如何去除标题栏title(转)

    去除标题栏title其实非常简单,他有两种方法,一种是在代码中添加,另一种是在AndroidManifest.xml中添加: 1.在代码中实现:在此方法setContentView(R.layout. ...

  10. 在Salesforce中将 Decimal 数据转换成美元格式

    闲言少叙,直接上代码(Apex Class 中的方法): private string ConvertToMoneyFormat(decimal price){ if (price == null | ...