E
E
EVOSandru62015-10-16 06:40:00
Yii
EVOSandru6, 2015-10-16 06:40:00

Why does jquery work differently in .js file and renderPartial file in Yii?

Good afternoon,
There is a _form.php file that is loaded from create.php via:
renderPartial('_form,['model'=>$model]);
In _form.php there are two elements with IDs:
#add-room and #fireball
There is some inconvenience,
From _form.php I can manipulate these elements:

alert($('#add-room').length + ' : ' + $('#fireball').length);

Returns:
1 : 1
But if I call this alert from scripts.js , then it does not see the target elements and returns:
0 : 0
And this is sad.
scripts.js is included in the footer of main theme main.php :
Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/js/scripts.js');

The strange thing is that all sorts of alert and $('*').hide(); in scripts.js are processed, also from _form.php you can call functions from scripts.js ...
On Google, I saw a similar problem, supposedly solved by adding this block before renderPartial (supposedly some js scripts are duplicated), but this did not solve the problem.
if (Yii::app()->request->isAjaxRequest)
{
  Yii::app()->getClientScript()->scriptMap =
    [
      'jquery.js' => false,
      'jquery.min.js' => false,
      'jquery-ui.min.js' => false,
      'jquery.ba-bbq.js'=>false,
      'jquery.yiigridview.js'=>false,
    ];
}

My scripts.js file without (function($) { ...
And jquery is processed there.
Kind people help with advice!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-10-16
@R0dger

try to wrap your function in timeout , set the time as you wish.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question