Dominykas55
Dominykas55

Reputation: 1231

Yii2 Fileinput widget initializing after renderAjax

I am completely lost for two days and have no clue how to fix this nonsense!

I use fileinput widget in my page like this:

            echo FileInput::widget([
                'name' => 'attachment_product[]',
                'id' => 'img_products',
                'options' => [
                    'multiple' => true
                ],
                'pluginOptions' => $pluginOptions,
            ]);

In the same page i have a button that when clicked, reloads the content with renderAjax.

On success i reload the content like this:

$('.content').html(data);

The problem is that the fileInput widget is not being initialized.. I dont know what to do and i get this error:

fileinput_516a5cfe is not defined

As i read here: https://github.com/kartik-v/yii2-widgets/issues/229 and here: https://github.com/kartik-v/yii2-widget-switchinput/issues/14. I need to reinitialize the plugin but I have no clue how to do that... I am lost..

Upvotes: 0

Views: 462

Answers (1)

Pave
Pave

Reputation: 2428

This is by design, A JavaScript file would typically only need loading once so all subsequent requests filter out already included files.

If you want to load it with every request you can add it's path to yii.reloadableScripts yii.js

https://github.com/yiisoft/yii2/issues/10251

Upvotes: 1

Related Questions