3

I had an issue when trying to incorporate multiple date picker which can be found here : http://multidatespickr.sourceforge.net/

The issue I had is explained in the following stackoverflow. : https://stackoverflow.com/questions/17920743/jquery-multiple-datepicker-selected-dates-not-loading-to-textbox

Since I didn't get any responses, I started digging in to code and figured out that yii's auto generating jQuery is the issue to all the problem.

So what I did is remove the following jQuery / jquery.min.js and included this. jquery-1.7.2.js

Now on console I get this eror

NetworkError: 404 Not Found - css/assets/819742eb/jquery.min.js"

but however I am able to get the multiple date picker worked which is my real need. :)

Now what I need is, since I just manually deleted and got this working but I wanted to know how to force a view file (index.php) in yii framework to load only the scripts that are defined in the page but not anything from main template or defined anywhere else.

Below is a html output and i only need the ones that are pointed in blue to be loaded inside a specific view.

enter image description here

Community
  • 1
  • 1
dev1234
  • 5,376
  • 15
  • 56
  • 115

2 Answers2

10

In your config in components array add

'clientScript' => array('scriptMap' => array('jquery.js' => false, ))

Then load what version you want in layout header:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

For yii 1.1.13 and lower and for jquery 1.9+ you'll need to patch jquery.ba-bbq to resolve some conflicts.

What you did (manually remove jquery) is very bad. Revert this.

To exclude some scripts use scriptmap. It can be used in controller before actions render and in config file.

All global scripts (jquery,jquery-ui etc.) must be in header in main layout. Load only custom scripts or plugins in your views.

ineersa
  • 3,445
  • 30
  • 40
  • tnx a lot. please can u show me an example of how to do this for a single action. i render the view like this. $controller->render('callDates', $params); so my action is class GetOutgoingCallDatesAction extends CAction { – dev1234 Jul 30 '13 at 07:42
  • Add `Yii::app()->clientScript->scriptMap['*.js'] = false;` before render in controller. It's used mostly to prevent double loads on ajax requests. Exclude js files in layout in other cases, it's good practice. – ineersa Jul 30 '13 at 08:17
  • i wrote this way the beforeRender. protected function beforeRender($view) { if ($this->action->id === 'getCallDates') { Yii::app()->clientScript->scriptMap = array( 'jquery.min.js' => false, ); } return parent::beforeRender($view); } – dev1234 Jul 30 '13 at 09:44
0

Add in config/main.php

'components' => [
    'clientScript' => ['scriptMap' => ['jquery.js' => 'http://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js']],
]
Mike S
  • 192
  • 3
  • 9