Answer the question
In order to leave comments, you need to log in
Conflict js scripts in Yii2 when working with forms, how to fix?
In general, I'm digging into Yii2 and came across this situation:
I broke my template into parts and there is a head.php part where scripts are connected in the usual way:
...
<script type="text/javascript" src="/js/jquery.cookies.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/main.js"></script>
...
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>
<script src="/assets/5ff4d296/jquery.js"></script>
<script src="/assets/28da076d/yii.js"></script>
<script src="/assets/28da076d/yii.validation.js"></script>
<script src="/assets/28da076d/yii.captcha.js"></script>
<script src="/assets/28da076d/yii.activeForm.js"></script>
<script type="text/javascript">jQuery(document).ready(function(){
jQuery('#contactform-verifycode-image').yiiCaptcha({"refreshUrl":"\/site\/c
...
Answer the question
In order to leave comments, you need to log in
You have two options:
Option 1. Collect all your scripts in an asset (see /assets/AppAsset.php for an example) and make the asset dependent on JqueryAsset:
public $depends = [
// 'yii\web\YiiAsset',
'yii\web\JqueryAsset',
];
'assetManager' => [
'bundles' => [
'yii\web\JqueryAsset' => [
'sourcePath' => null,
'js' => ['//code.jquery.com/jquery-1.11.0-beta3.min.js'] // тут путь до Вашего экземпляра jquery
],
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question