2014-10-06 123 views
2

我正在使用ExtJS版本4.1.1。提交表单时重置文件上传字段

我尝试使用的FileField如下创建上传文件格式:

{ 
    xtype: 'filefield', 
    itemId : 'my-file', 
    name: 'my file', 
    emptyText : 'No file chosen', 
    fieldLabel: 'Upload File', 
    submitValue: true, 
    allowBlank : false, 
    buttonText: 'Browse', 
    listeners: { 
     change: function(fld, value) { 
      var newValue = value.replace(/C:\\fakepath\\/g, ''); 
      fld.setRawValue(newValue); 
     } 
    } 
} 

当表单提交后,filefield复位。

正如我在 http://www.sencha.com/forum/showthread.php?135109-File-upload-field-is-empty-by-re-submitting-of-the-form

看到我尝试重写filefield到:

Ext.override(Ext.form.field.File, { 
    extractFileInput: function() { 
     var me = this, 
      fileInput = me.fileInputEl.dom, 
      clone = fileInput.cloneNode(true); 

     fileInput.parentNode.replaceChild(clone, fileInput); 
     me.fileInputEl = Ext.get(clone); 

     me.fileInputEl.on({ 
      scope: me, 
      change: me.onFileChange 
     }); 

     return fileInput; 
} 

它看起来确定,当我提交表单。

我在文本框中看到的值未被重置为空。

但是,当我再次提交表单而没有重新选择文件时,发送到服务器的数据为空。

应该保留发送到服务器的数据。

附加信息:当我用Chrome和IE

此问题发生,它似乎在Firefox做工精细。

是否与C:\\fakepath我在文本框中看到选择文件时相关?

我该如何解决这个问题?

回答

7

设置为clearOnSubmitfalse您的filefield