gpt4 book ai didi

javascript - clearOnSubmit false 的文件字段仍被清除

转载 作者:行者123 更新时间:2023-12-02 14:12:45 25 4
gpt4 key购买 nike

由于 filefield 组件出现严重问题,我从 ExtJs 4.1 迁移到 ExtJs 4.2。主要问题是在 ExtJs 4.1 中,每次表单提交后文件字段都会被清除。据此thread ,在 ExtJs 4.2 中,他们解决了这个问题,但是,尽管我将 clearOnSubmit 设置为 false,但我在应用程序中仍然面临同样的问题。我什至弄清楚是什么代码导致了整个问题:

 Ext.define('Ext.form.field.FileButton', {
...
createFileInput : function(isTemporary) {
var me = this;
//ATTENTION!
//before me.el.createChild is called
//me.fileInputEl contains initial filefield:
//<input id="filefield-2144-button-fileInputEl" class=" x-form-file-input" type="file" size="1" name="file_name" role="">
me.fileInputEl = me.el.createChild({
name: me.inputName,
id: !isTemporary ? me.id + '-fileInputEl' : undefined,
cls: me.inputCls,
tag: 'input',
type: 'file',
size: 1
});
//ATTENTION!
//now initial fielfield is gone, even though we have set clearOnSubmit to false
me.fileInputEl.on('change', me.fireChange, me);
}
...

当表单提交到服务器并销毁初始元素时,会在某个时刻调用此库方法:

 <input id="filefield-2144-button-fileInputEl" class=" x-form-file-input" type="file" size="1" name="file_name" role="">

并将其替换为新的空的:

<input name="file_name" id="ext-gen4414" class="x-form-file-input" type="file" size="1">

那么,这有什么问题以及如何修复这个库错误。

最佳答案

我在4.2.1上测试过。它工作正常。提交后文件字段没有被清除。

Ext.application({
name: 'Fiddle',

launch: function() {
Ext.create('Ext.form.Panel', {
title: 'Upload a Photo',
width: 400,
bodyPadding: 10,
frame: true,
renderTo: Ext.getBody(),
items: [{
xtype: 'filefield',
name: 'photo',
fieldLabel: 'Photo',
labelWidth: 50,
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: 'Select Photo...',
clearOnSubmit: false
}],

buttons: [{
text: 'Upload',
handler: function() {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
url: 'photo-upload.php',
waitMsg: 'Uploading your photo...',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');
}
});
}
}
}]
});
}
});

关于javascript - clearOnSubmit false 的文件字段仍被清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39362007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com