2amigos/yiiwheels

Events configuration for WhFineUploader

Closed this issue · 2 comments

How do we configure events for WhFineUploader? I tried this code, but it didn't work:

$this->widget('yiiwheels.widgets.fineuploader.WhFineUploader', array(
    'name'=>'picture-upload',
    'uploadAction'=>$this->createUrl('user/upload', array('id'=>$model->id)),
    'pluginOptions'=>array(
        'validation'=>array(
            'allowedExtensions'=>array('jpeg', 'jpg', 'gif', 'png')
        ),
        'onSubmit'=>"js: function(id, fileName) { 
            alert('xx'); 
        }",
        'onComplete'=>"js: function(id, fileName, responseJSON) {
            alert('xx');
        }",
    )
));

'onSubmit' and 'onComplete' events were not fired, but file uploading worked fine. Am I doing anything wrong?

The settings are wrong, you should set the events attribute https://github.com/2amigos/yiiwheels/blob/master/widgets/fineuploader/WhFineUploader.php#L38 and not within the pluginOptions

Sorry, I thought events attribute should be set like normal plugin options. So, here is the working one:

$this->widget('yiiwheels.widgets.fineuploader.WhFineUploader', array(
    'name'=>'picture-upload',
    'uploadAction'=>$this->createUrl('user/upload', array('id'=>$model->id)),
    'events'=>array(
        'submit'=>"function() { alert('xx'); }",
        'complete'=>"function() { alert('xx'); }",
    ),
    'pluginOptions'=>array(
        'validation'=>array(
            'allowedExtensions'=>array('jpeg', 'jpg', 'gif', 'png')
        ),
    )
));

Many thanks for your help, Antonio.