【发布时间】:2014-10-06 07:42:22
【问题描述】:
我使用的是 ExtJS 版本 4.1.1。
我尝试使用以下文件字段创建上传文件表单:
{
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 被重置。
我尝试将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 有关吗?
我该如何解决这个问题?
【问题讨论】:
标签: extjs file-upload filefield