78 if (!empty($this->htmlOptions[
'readonly'])) {
79 $this->readonly =
true;
81 if (!empty($this->htmlOptions[
'disabled'])) {
82 $this->disabled =
true;
93 list($name, $id) = $this->resolveNameID();
95 if ($this->hasModel()) {
97 echo $this->asDropDownList
99 $this->form->dropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions)
101 $this->form->hiddenField($this->model, $this->attribute, $this->htmlOptions);
103 echo $this->asDropDownList
105 CHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions)
107 CHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
111 echo $this->asDropDownList
113 CHtml::dropDownList($name, $this->
value, $this->data, $this->htmlOptions)
115 CHtml::hiddenField($name, $this->
value, $this->htmlOptions);
131 $options = !empty($this->options) ? CJavaScript::encode($this->options) :
'';
133 if(! empty($this->val)) {
134 if(is_array($this->val)) {
135 $data = CJSON::encode($this->val);
140 $defValue =
".select2('val', $data)";
145 if ($this->readonly) {
146 $defValue .=
".select2('readonly', true)";
148 elseif ($this->disabled) {
149 $defValue .=
".select2('enable', false)";
153 echo
"jQuery('#{$id}').select2({$options})";
154 foreach ($this->events as $event => $handler) {
155 echo
".on('{$event}', " . CJavaScript::encode($handler) .
")";
159 Yii::app()->getClientScript()->registerScript(__CLASS__ .
'#' . $this->getId(), ob_get_clean() .
';');
164 if (empty($this->options[
'width'])) {
165 $this->options[
'width'] =
'resolve';
172 $this->data = array();
177 if (!empty($this->htmlOptions[
'placeholder']))
178 $this->options[
'placeholder'] = $this->htmlOptions[
'placeholder'];
180 if (!empty($this->options[
'placeholder']) && empty($this->htmlOptions[
'multiple']))
186 if (empty($this->options)) {
187 $this->options = array();