【问题标题】:File upload field is reset when submit form提交表单时重置文件上传字段
【发布时间】: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 被重置。

正如我所见 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 有关吗?

我该如何解决这个问题?

【问题讨论】:

    标签: extjs file-upload filefield


    【解决方案1】:

    在您的filefield 上将clearOnSubmit 设置为false

    【讨论】:

      猜你喜欢
      • 2016-03-31
      • 2013-09-16
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 1970-01-01
      • 2019-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多