Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

fieldOptions-accept not working well #116

Closed
robov opened this issue Aug 27, 2017 · 9 comments
Closed

fieldOptions-accept not working well #116

robov opened this issue Aug 27, 2017 · 9 comments

Comments

@robov
Copy link

robov commented Aug 27, 2017

When I limit the fieldoptions to accept only pdf I get a file select limitation (I can only select pdf from my computer), however when I type in a name xx.zip.. then I can still upload that zip file.
The demo on blueimp has somewhere a check before the upload and prevents uploading the wrong filetype

@tonydspaniard
Copy link
Member

@robov
Copy link
Author

robov commented Aug 27, 2017

Thanks...yes I found that but how do I set that in your widget settings ?

@robov
Copy link
Author

robov commented Aug 27, 2017

And there seems to be alot of validation going on in the bluimp uploadhandler that is missing in your demo implementation... https://github.com/blueimp/jQuery-File-Upload/blob/master/server/php/UploadHandler.php

@tonydspaniard
Copy link
Member

tonydspaniard commented Aug 27, 2017

And there seems to be alot of validation going on in the bluimp uploadhandler that is missing in your demo implementation...

The upload handler of jquery file upload certainly doesn't use Yii2 validation capabilities. We need to combine both.

Thanks...yes I found that but how do I set that in your widget settings ?

Everything on the plugin documentation can be set throughout clientOptions. In fact, clientOptions transforms to the plugin configuration.

@robov
Copy link
Author

robov commented Aug 27, 2017

Cool... I could assume that , but I could not find it.

@robov
Copy link
Author

robov commented Aug 27, 2017

when I set it:

    'clientOptions' => [
        'maxFileSize' => 10000 * $FilesizeGB ,
        'maxChunkSize' => 1 * $FilesizeMB,
        'maxNumberOfFiles' => 2,    
        'acceptFileTypes' => '/(\.|\/)(gif|jpe?g|png)$/i',
    ],

I get

Uncaught TypeError: options.acceptFileTypes.test is not a function

@tonydspaniard
Copy link
Member

tonydspaniard commented Aug 27, 2017

@robov you need to setup a valid regular expression. Therefore you need to use new JsExpression:

'clientOptions' => [
        'maxFileSize' => 10000 * $FilesizeGB ,
        'maxChunkSize' => 1 * $FilesizeMB,
        'maxNumberOfFiles' => 2,    
        'acceptFileTypes' => new JsExpression('/(\.|\/)(gif|jpe?g|png)$/i'),
    ],

more here: https://github.com/blueimp/jQuery-File-Upload/wiki/Options#acceptfiletypes

@robov
Copy link
Author

robov commented Aug 27, 2017

AWESOME... thank you so much please include that in your demo, so other people won't have to struggle finding it....

@tonydspaniard
Copy link
Member

AWESOME... thank you so much please include that in your demo, so other people won't have to struggle finding it....

PRs are always welcome

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants