/** * Registers the asset bundle and locale */ public function registerAssetBundle() { $view = $this->getView(); $lang = isset($this->language) ? $this->language : ''; Select2Asset::register($view)->addLanguage($lang, '', 'js/i18n'); if (in_array($this->theme, self::$_inbuiltThemes)) { $bundleClass = __NAMESPACE__ . '\\Theme' . ucfirst($this->theme) . 'Asset'; $bundleClass::register($view); } }
/** * Registers the asset bundle and locale */ protected function registerAssetBundle() { $view = $this->getView(); if (!empty($this->language) && substr($this->language, 0, 2) != 'en') { $path = __DIR__ . '/lib'; $file = "select2_locale_{$this->language}.js"; if (!Config::fileExists("{$path}/{$file}")) { $file = "select2_locale_{$this->_lang}.js"; } if (Config::fileExists("{$path}/{$file}")) { Select2Asset::register($view)->js[] = $file; return; } } Select2Asset::register($view); }
<?php use yii\helpers\Url; use yii\helpers\Html; use yii\bootstrap\Modal; use kartik\grid\GridView; use johnitvn\ajaxcrud\CrudAsset; use johnitvn\ajaxcrud\BulkButtonWidget; use kartik\select2\Select2; \kartik\select2\Select2Asset::register($this); $js = <<<'JS' $("#unique-pjax-id").on("pjax:complete", function() { alert('ssss'); var $el = $("#unique-select2-id"), ll=$("#unique-select2-id"); alert(ll.data); options = $el.data('pluginOptions'); // select2 plugin settings saved jQuery.when($el.select2(window[options])).done(initSelect2Loading('unique-select2-id')); }); JS; // Call the above js script in your view $this->registerJs($js); /* @var $this yii\web\View */ /* @var $searchModel app\models\AcEspUejSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Ac Esp Uejs'; $this->params['breadcrumbs'][] = $this->title; CrudAsset::register($this); ?> <div class="ac-esp-uej-index"> <div id="unique-pjax-id">
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use kartik\select2\Select2; use kartik\select2\Select2Asset; $rules = Yii::$app->authManager->getRules(); $rulesNames = array_keys($rules); $rulesDatas = array_merge(['' => Yii::t('rbac', '(not use)')], array_combine($rulesNames, $rulesNames)); $authManager = Yii::$app->authManager; $permissions = $authManager->getPermissions(); Select2Asset::register($this); ?> <div class="auth-item-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'description')->textarea(['rows' => 1]); ?> <?php echo $form->field($model, 'ruleName')->dropDownList($rulesDatas);
/** * Registers the needed assets */ public function registerAssets() { $view = $this->getView(); $id = $this->options['id']; // set locale and language if (!empty($this->language) && substr($this->language, 0, 2) != 'en') { Select2Asset::register($view)->js[] = 'select2_locale_' . $this->language . '.js'; } else { Select2Asset::register($view); } // set default width $this->pluginOptions['width'] = 'resolve'; // validate bootstrap has-success & has-error states $this->pluginEvents += ['select2-open' => "function(){initSelect2DropStyle('{$id}')}"]; // register plugin if ($this->pluginLoading) { $this->registerPlugin('select2', "jQuery('#{$id}')", "initSelect2Loading('{$id}')"); } else { $this->registerPlugin('select2'); } }
/** * Registers the asset bundle and locale */ public function registerAssetBundle() { $view = $this->getView(); Select2Asset::register($view)->addLanguage($this->language, 'select2_locale_', '/'); }