/** * */ public function init() { if (empty($this->parentName)) { throw new InvalidParamException('RelativeSelect2 $parentName must be set!'); } if (empty($this->url)) { throw new InvalidParamException('RelativeSelect2 $url must be set!'); } if ($this->parentModel instanceof Model) { $this->options['data']['select2-parent-name'] = Html::getInputName($this->parentModel, $this->parentName); } else { $this->options['data']['select2-parent-name'] = $this->hasModel() ? Html::getInputName($this->model, $this->parentName) : $this->parentName; } if (is_array($this->url)) { $this->url = Url::to($this->url); } $this->options['data']['select2-url'] = $this->url; if (!empty($this->model) && isset($this->model->{$this->attribute})) { if (is_array($this->model->{$this->attribute})) { $this->options['data']['select2-selected-items'] = implode(',', $this->model->{$this->attribute}); } else { $this->options['data']['select2-selected-items'] = $this->model->{$this->attribute}; } } else { $this->options['data']['select2-selected-items'] = $this->value; } parent::init(); RelativeSelect2Asset::register($this->getView()); }
public function init() { $this->setDefaultOptions(); if ($this->getSelect2Type() == 'ajax') { $this->setAjaxOptions(); } parent::init(); }
public function init() { $allValuesTmp = $this->view->params[$this->name . "_all"]; foreach ($allValuesTmp as $v) { $allValuesTmp2[$v] = $v; } $selectedValuesTmp = $this->view->params[$this->name]; if ($selectedValuesTmp) { foreach ($selectedValuesTmp as $v) { $selectedValuesTmp2[$v] = $v; } } else { $selectedValuesTmp2 = null; } $this->data = $allValuesTmp2; $this->value = $selectedValuesTmp2; $this->options = ['multiple' => true, 'placeholder' => $this->initialText]; parent::init(); }