Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to select multiple files in the file upload window with extjs 5?

Is it possible to select multiple files in the file upload window using extjs 5?

like image 787
Phi Avatar asked Nov 11 '22 06:11

Phi


2 Answers

Just adding attribute multiple:'' like this:

var fileUploadButton = new Ext.create('Ext.form.field.File', {
        buttonOnly: true,
        hideLabel: true,
        buttonText: 'Upload Files...',
        fileInputAttributes: {
            accept: 'application/xml',
            multiple: ''
        });
like image 161
Phi Avatar answered Nov 14 '22 23:11

Phi


If you want to show names of the files you can make something like this:

Ext.define('Ext.form.field.MyFile', {
    extend: 'Ext.form.field.File',
    alias: 'widget.multiplefileuploadfield',

    multiple: true,

    afterRender: function(){
        var me = this;

        me.callParent(arguments);

        if(me.multiple){
            me.fileInputEl.set({
                multiple:'multiple',
                name: me.name ? me.name + '[]' : 'files[]'
            });
        }
    }
});

Ext.define('Ext.form.field.FileButtonOverride', {
    override: 'Ext.form.field.FileButton',

    fireChange: function(e){
        var inp = this.fileInputEl.dom;

        if(!inp.files || !window.FileReader || !inp.files.length){
            this.fireEvent('change', this, e, inp.value);
            return;
        }

        var arrValues = [];
        for (var i = 0; i < inp.files.length; ++i) {
            arrValues.push(inp.files.item(i).name);
        }

        this.fireEvent('change', this, e, arrValues.join(', '));
    }
});
like image 34
Paul Pogodin Avatar answered Nov 14 '22 21:11

Paul Pogodin