2amigos / yiiwheels

Widget extension library for the YiiStrap extension
http://yiiwheels.2amigos.us
Other
133 stars 77 forks source link

Events configuration for WhFineUploader #78

Closed re1naldo closed 10 years ago

re1naldo commented 10 years ago

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?

tonydspaniard commented 10 years ago

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

re1naldo commented 10 years ago

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.