Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File upload field is reset when submit form

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?

like image 343
Gui Avatar asked Dec 25 '22 03:12

Gui


1 Answers

set clearOnSubmit to false on your filefield

like image 143
Christophe Le Besnerais Avatar answered Jan 11 '23 14:01

Christophe Le Besnerais