kartik-v / yii2-widget-select2

Enhanced Yii2 wrapper for the Select2 jQuery plugin (sub repo split from yii2-widgets).
http://demos.krajee.com/widget-details/select2
Other
323 stars 145 forks source link

Uncaught ReferenceError: select2_d648201d is not defined #129

Closed harshitchaudhary closed 8 years ago

harshitchaudhary commented 8 years ago

I am facing some JS issues not sure why they are. I am attaching a screenshot of console

screenshot from 2016-03-05 17 15 09

Thanks in advance

kartik-v commented 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).

AlikKosarevskiy commented 8 years ago

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.

harshitchaudhary commented 8 years ago

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. screenshot from 2016-05-21 14-17-41

AlikKosarevskiy commented 8 years ago

Thank you guys, it works now!

onovikov09 commented 7 years ago

Hello! I had a problem in that I in a template deleted a call $this->head().

maskeyarun commented 6 years ago

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:

field($modelMeta, 'rate')->textInput(['maxlength' => true])->label(FALSE) ?>
                <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(); ?>

field($meta, 'particular[]')->widget(Select2::classname(), [ 'data' => $rawList, 'language' => 'en', 'options' => ['placeholder' => 'Select Raw material ...', 'class' => 'sitem', 'id' => 'rawid' . $key], 'pluginOptions' => [ 'allowClear' => true ], ])->label(FALSE); ?> field($meta, 'unit[]')->widget(Select2::classname(), [ 'data' => $unitList, 'language' => 'en', 'options' => ['placeholder' => 'Select Unit ...', 'class' => 'sitem', 'id' => 'unitid' . $key], 'pluginOptions' => [ 'allowClear' => true ], ])->label(FALSE); ?> field($meta, 'rate[]')->textInput(['maxlength' => true])->label(FALSE) ?> field($meta, 'qty[]')->textInput()->label(FALSE) ?> field($meta, 'amount[]')->textInput(['maxlength' => true])->label(FALSE) ?>
maskeyarun commented 5 years ago

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 .

ghost commented 4 years ago

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()