kartik-v / yii2-widget-fileinput

An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)
Other
229 stars 96 forks source link

Plugin methods not available in change event #175

Closed ItsReddi closed 3 years ago

ItsReddi commented 3 years ago

The issue is described in: https://github.com/kartik-v/bootstrap-fileinput/issues/1550

We also discovered this Bug. Thanks for the timeout hint. Idea: (not confirmed) The issue is maybe related to the 'destroy' initiated by WidgetTrait. grafik

Originally posted by @ItsReddi in https://github.com/kartik-v/bootstrap-fileinput/issues/1550#issuecomment-772588908

Not working

                   $form
                    ->field($model, 'file')
                    ->widget(FileInput::class, [
                        'options' => [
                            'multiple' => false,
                        ],
                        'pluginOptions' => [
                            'showPreview' => false,
                            'showCaption' => false,
                            'showRemove' => false,
                            'showUpload' => false,
                            'browseClass' => 'btn btn-default',
                            'uploadUrl' => Url::to(['upload']),
                        ],
                        'pluginEvents' => [
                                'change' => 'function(event) { $("#file-file").fileinput("upload"); }'
                        ]
                    ])
                    ->label(false);

Working

                   $form
                    ->field($model, 'file')
                    ->widget(FileInput::class, [
                        'options' => [
                            'multiple' => false,
                        ],
                        'pluginOptions' => [
                            'showPreview' => false,
                            'showCaption' => false,
                            'showRemove' => false,
                            'showUpload' => false,
                            'browseClass' => 'btn btn-default',
                            'uploadUrl' => Url::to(['upload']),
                        ],
                        'pluginEvents' => [
                                'change' => 'function(event) { setTimeout(function() {$("#file-file").fileinput("upload");}, 500); }'
                        ]
                    ])
                    ->label(false);

Environment

Browsers

Operating System

Libraries

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/97495668-plugin-methods-not-available-in-change-event?utm_campaign=plugin&utm_content=tracker%2F8184669&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F8184669&utm_medium=issues&utm_source=github).
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.