Closed harshitchaudhary closed 8 years ago
You need to debug your code (basically JS dependencies and how you are loading your core assets e.g. jQuery assets, and other plugins).
If you are loading content by AJAX you need to ensure you have the dependent content loaded in HEAD and use appropriate methods like renderAjax to render content if needed (to ensure the dependencies are loaded).
Hi harshitchaudhary! Do you find the solution for your trouble? I have the same Uncaught ReferenceError: select2_11dcd82c is not defined, and start to investigate.
Yeah, actually I followed whatever @kartik-v have mentioned and thereafter it worked. Just make sure your register your jquery and select2.js before registering your class or id with select2
Here is my working sequence. I hope you might get some idea with that.
Thank you guys, it works now!
Hello! I had a problem in that I in a template deleted a call $this->head().
I'm using with AJAX and getting same problem. Please suggest where should I inject the dependencies. There is a clone button and once the RenderAjax get's cloned it will append result into a table. first page:
<td><?= $form->field($modelMeta, 'qty')->textInput()->label(FALSE) ?></td>
<td><?= $form->field($modelMeta, 'amount')->textInput(['maxlength' => true])->label(FALSE) ?></td>
<td>
<span class="btn btn-primary glyphicon glyphicon-plus-sign " onclick="pometaclone()"></span>
<span class="btn btn-danger glyphicon glyphicon-minus-sign hide minus" onclick="$(this).closest('tr').remove();"></span>
</td>
</tr>
</tbody>
</table>
<?= $form->field($model, 'purchaseterm')->textarea(['rows' => 6]) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php $this->registerJs($this->render('po.js'), \yii\web\View::POS_HEAD);
=========== Controller public function actionPorawclone($purcount) { $meta = new \app\models\PurchaseOrdermeta(); $rawList = ArrayHelper::map(\app\models\MasterRawitems::find()->all(), 'id', 'raw_name'); $unitList = ArrayHelper::map(\app\models\InventoryUnits::find()->all(), 'id', 'unitcode'); return $this->renderAjax('porawclone', [ 'meta' => $meta, 'rawList' => $rawList, 'unitList' => $unitList, 'key' => $purcount ]); } ======================Ajax rendered <?php
use kartik\select2\Select2; use yii\bootstrap\ActiveForm; ?> <?php $form = ActiveForm::begin(); ?>
I got same problem a year a go, after I declared that in script it worked fine.
Did it come while there are multie select2
On Mon, 29 Jul 2019, 15:07 Fredy Nurman Saleh, notifications@github.com wrote:
does anyone trying this lately? seems there is some script try to mention undefined variable.
in some line mentioned as (in my case):
window.select2_21c9e67b = {"allowClear":true,"tags":false,"minimumInputLength":2,"lang...};
but later script mentioned as:
jQuery.when(jQuery('#book-author_id').select2(select2_21c9e67b)).done(initS2Loading('book-author_id','s2options_d6851687'));
can anyone help?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kartik-v/yii2-widget-select2/issues/129?email_source=notifications&email_token=ABWAE6UQ5TSXPFSE54O3PXDQB2ZHFA5CNFSM4B5H5H2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3AEA6Q#issuecomment-515915898, or mute the thread https://github.com/notifications/unsubscribe-auth/ABWAE6QQLJAJB4QKPGZZHQ3QB2ZHFANCNFSM4B5H5H2A .
It occurred to me as I did not close my form .
$form = ActiveForm::begin([
'enableAjaxValidation' => false,
]);
echo Select2::widget([
'id' => $selector,
'name' => 'Name',
'data' =>[],
'options' => [
'multiple' => false,
'placeholder' => Yii::t('app', 'Select')
]
]);
should be end with
TActiveForm::end()
I am facing some JS issues not sure why they are. I am attaching a screenshot of console
Thanks in advance