File upload field is reset when submit form

巧了我就是萌 提交于 2019-12-13 14:51:50

问题


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?


回答1:


set clearOnSubmit to false on your filefield



来源:https://stackoverflow.com/questions/26211812/file-upload-field-is-reset-when-submit-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!