jQuery(...).activeform is not a function in Yii
Asked Answered
A

4

8

I am developing a project with Yii.

I need to use jquery ui on many pages of site. So I add jquery core library and jquery ui library in the layout of site to have access to them on all the pages.

But it causes problem on the pages which have a form (active form). I see this error on the firebug :

jQuery(...).activeform is not a function

why is it so? How can I resolve it?

Thank you.

Audiophile answered 30/5, 2013 at 8:51 Comment(3)
Have you added activeform.js jQuery plugin too?Lymphatic
It's called yiiactiveform, not just activeform.Columbarium
Just found out the same what Jon did. It's yiiactiveform. ;)Lymphatic
D
14

If you include jQuery core libraries manually in your layout file, it could be possible that jQuery gets loaded a second time and overrides the original jQuery object which had the Yii plugins attached.

You should use Yii::app()->clientScript->registerCoreScript('jquery.ui') instead.

Dustproof answered 30/5, 2013 at 10:24 Comment(2)
Where should I add this lineExhilarate
The question was about the layout file, so you'd look for some file in protected/views/layouts.Infrasonic
E
0

You might have loaded the jquery twice in your page, please check the your code in layout/main.php and where ever you have registered jquery. To load the jquery default code in yii is something like as follows

Yii::app()->clientScript

Please check this line, if you are loading jquery here and you might have loaded the jquery in your layout also. Best way to check this is to use html debugger and view page source of the same page where you are getting error.

Estrone answered 15/12, 2016 at 7:54 Comment(0)
K
0

add this code with yours path to js in head.php

<?php YII_DEBUG === true ? Yii::app()->clientScript->scriptMap = array('jquery.js'=>'/js/jquery-3.3.1.js') : Yii::app()->clientScript->scriptMap = array('jquery.min.js'=>'/js/jquery-3.3.1.min.js') ?>
<?php Yii::app()->getClientScript()->registerCoreScript('jquery'); ?>
Knut answered 18/7, 2018 at 9:53 Comment(0)
P
0

Make a file in the js folder with the name yii.activeForm.js and copy the contents from https://codeclimate.com/github/yiisoft/yii2/framework/assets/yii.activeForm.js/source.

Don't forget to include the file in AppAsset.php.

Pyrotechnics answered 23/11, 2021 at 6:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.