D
D
Dmitriy G2019-10-21 09:58:48
Yii
Dmitriy G, 2019-10-21 09:58:48

Why doesn't the script file fire a second time in the modal window?

Page is loaded via renderAjax()

return [     
  'content'=>$this->renderAjax('update', [
   'model' => $model,  ]),            
             ];

View update has script registration
$this->registerJsFile('/js/script.js',['depends' => 'yii\web\JqueryAsset']);

But when the modal window is called, the scripts work only once, when the modal window is subsequently called, the scripts do not work, although the developer console shows that the files are overwritten
$script = <<<JS
alert('test')
JS;
$this->registerJs($script);

render() and renderPartial() don't help
UPD: a page with a gridview where each entry has a view in a modal window.
The first time the modal is loaded, the scripts that are registered in the modal's view are fired.
But when you close this modal window and launch the modal window of the same post again or another post, the scripts do not work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vitaly_74, 2019-10-21
@vitaly_74

try writing all js in files, then if you use jquery then for each processing do this: $(document).on("click", "selector", function(){});
The fact is that when you load something via ajax, it will work exactly once, i.e. after updating the data, jqury stops seeing what is drawn again. the code above helps solve this problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question