innostudio / fileuploader

Beautiful and powerful HTML file uploading tool. A jQuery, PHP and Node.js plugin that transforms the standard input into a revolutionary and fancy field on your page.
141 stars 25 forks source link

Validate extension #38

Closed tornako closed 5 years ago

tornako commented 5 years ago

Hi,

I want to validate the extensions with a function because I have several forms of files and images, and depending on what is used, I must allow one extension or another.

Can you give me an idea of ​​how to do it?

I imagine that with the following:

` onFilesCheck: function(files, options, listEl, parentEl, newInputEl, inputEl) {

        if(inputEl.attr('data-apt') == 'logotip'){
            alert('form 1');
            disallowedExtensions: ['text/plain', 'audio/*']
        } else {
            alert('form 2');
            disallowedExtensions: ['jpg', 'jpeg', 'png']
        }

        return true;
    },

`

The alerts are working, but not the dissallowedExtensions.

Thanks!

innostudio commented 5 years ago

@tornako we would recommend you the following code:

enableApi: true,
afterRender: function(listEl, parentEl, newInputEl, inputEl) {
    var api = $.fileuploader.getInstance(inputEl);

    if (inputEl.attr('data-apt') == 'logotip')
        api.getOptions().disallowedExtensions = ['text/plain', 'audio/*'];
     else
        api.getOptions().disallowedExtensions = ['jpg', 'jpeg', 'png'];
},
tornako commented 5 years ago

Thanks, it's working!

:)