/** * Executes the widget. */ public function run() { if ($this->hasModel()) { if ($this->asDropdownList) { echo Html::activeDropDownList($this->model, $this->attribute, $this->data, $this->options); } else { if (!isset($this->clientOptions['query']) && !isset($this->clientOptions['ajax']) && !isset($this->clientOptions['data'])) { throw new InvalidConfigException('Must be set at least one of the client options: query, data, ajax.'); } echo Html::activeHiddenInput($this->model, $this->attribute, $this->options); } } else { if ($this->asDropdownList) { echo Html::dropDownList($this->name, $this->value, $this->data, $this->options); } else { if (!isset($this->clientOptions['query']) && !isset($this->clientOptions['ajax']) && !isset($this->clientOptions['data'])) { throw new InvalidConfigException('Must be set at least one of the options Select2: query, data, ajax.'); } echo Html::hiddenInput($this->name, $this->value, $this->options); } } Select2Asset::register($this->view); $this->registerPlugin('select2'); }
/** * @inheritdoc */ public static function activeDropDownList($model, $attribute, $items, $options = []) { if (array_key_exists('select2me', $options) && $options['select2me'] == false) { } else { Select2Asset::register(\Yii::$app->view); self::addCssClass($options, self::CLASS_SELECT2ME); } self::addData($options, 'placeholder', '-'); return parent::activeDropDownList($model, $attribute, $items, $options); }