I disabled all Yii dependencies in AppAsset and config/web.php:
public $css = [
//'css/site.css',
'css/ui.css',
'css/additional.css',
];
public $js = [
'js/vendor/jquery.min.js',
'js/vendor/bootstrap.min.js',
'js/ui.js',
'js/app.js',
];
public $depends = [
//'yii\web\YiiAsset',
// 'yii\bootstrap\BootstrapAsset',
];
and
'assetManager' => [
'appendTimestamp' => true,
'bundles' => [
'yii\web\YiiAsset' => [
'js'=>[]
],
'yii\widgets\ActiveFormAsset' => [
'js'=>[]
],
'yii\web\JqueryAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapPluginAsset' => [
'js'=>[]
],
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
],
],
],
But I still have this JS code at the bottom of pages where I have active forms:
<script type="text/javascript">jQuery(document).ready(function () {
--
聽 | jQuery('#edit-form').yiiActiveForm([], {"validateOnSubmit":false});
聽 | jQuery('#password-form').yiiActiveForm([], {"validateOnSubmit":false});
聽 | });</script>
Therefore:
1) I don't have connected yiiActiveForm.js
2) I have JS snippet which tries to call yiiActiveForm.js
3) I have the following error in Chrome's console:
Uncaught TypeError: jQuery(...).yiiActiveForm is not a function
| Q | A
| ---------------- | ---
| Yii version | 2.0.12
| PHP version | 5.6.26
| Operating system | Windows 10
I.e. active form must check you dependences and generated code must depends on it?
Or you wish avoid the error with fake JQuery plugin like this?
(function ($) {
$.fn.yiiActiveForm = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.yiiActiveForm');
return false;
}
};
var methods = {
init: function (attributes, options) {
}
};
})(window.jQuery);
If I fully disabled all Yii JS dependencies, there mustn't be any JS code related to Yii JS.
This JS code is unnecessary in this case:
<script type="text/javascript">jQuery(document).ready(function () {
--
| jQuery('#edit-form').yiiActiveForm([], {"validateOnSubmit":false});
| jQuery('#password-form').yiiActiveForm([], {"validateOnSubmit":false});
| });</script>
@bohdan-vorona If you disable assets this only disables inclusion of yiiActiveForm.js. It does not prevent the init snippet in the HTML source.
Try setting enableClientScript to false on your ActiveForm instead.
<?php $form = ActiveForm::begin([
'enableClientScript' => false,
]); ?>
/**
* @var bool whether to hook up `yii.activeForm` JavaScript plugin.
* This property must be set `true` if you want to support client validation and/or AJAX validation, or if you
* want to take advantage of the `yii.activeForm` plugin. When this is `false`, the form will not generate
* any JavaScript.
* @see registerClientScript
*/
public $enableClientScript = true;
@bscheshirwork @mikehaertl Thanks for recommendations. It's working.
Most helpful comment