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
復位。
看到我嘗試重寫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
我在文本框中看到選擇文件時相關?
我該如何解決這個問題?