提交表单时重置文件上传字段 [英] File upload field is reset when submit form
问题描述
我尝试使用filefield创建上传文件格式如下:
{
xtype:'filefield',
itemId:'my-file',
name:'my file',
emptyText:'没有选择文件',
fieldLabel:'上传文件',
submitValue:true,
allowBlank:false,
buttonText:'Browse',
听众:{
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
在我选择文件时在文本框中看到相关
解决方案 set clearOnSubmit
to false 您的文件夹
I am using ExtJS version 4.1.1.
I try to create upload file form using filefield as follow:
{
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);
}
}
}
When the form is submitted, the filefield
is reset.
As I see in
http://www.sencha.com/forum/showthread.php?135109-File-upload-field-is-empty-by-re-submitting-of-the-form
I try to override the filefield
to :
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;
}
It look OK when I submit the form.
The value that I see in the textfield is not reset to empty.
However, when I submit the form again without re-choose file, the data that be sent to the server is null.
The data that be sent to the server should be retained.
Additional Info:
This problem occur when I use Chrome and IE, It seem work fine on Firefox.
Is it related with C:\\fakepath
that I see on textfield when choose file?
How can I fix this problem?
解决方案 set clearOnSubmit
to false
on your filefield
这篇关于提交表单时重置文件上传字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!