/**
* Runs the widget.
*/
public function run()
{
list($name, $id) = $this->resolveNameID();
$id = $this->resolveId($id);
echo TbHtml::openTag('div', array('class' => 'select2'));
if ($this->hasModel()) {
if ($this->asDropDownList) {
echo TbHtml::activeDropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
} else {
echo TbHtml::activeHiddenField($this->model, $this->attribute, $this->htmlOptions);
}
} else {
if ($this->asDropDownList) {
echo TbHtml::dropDownList($name, $this->value, $this->data, $this->htmlOptions);
} else {
echo TbHtml::hiddenField($name, $this->value, $this->htmlOptions);
}
}
echo '</div>';
if ($this->assetPath !== false) {
$this->publishAssets($this->assetPath);
$this->registerCssFile('/select2.css');
if ($this->registerJs) {
$this->registerScriptFile('/select2.js', CClientScript::POS_END);
}
}
if ($this->bindPlugin) {
$options = !empty($this->pluginOptions) ? CJavaScript::encode($this->pluginOptions) : '';
$this->getClientScript()->registerScript(__CLASS__ . '#' . $id, "jQuery('#{$id}').select2({$options});");
}
}