diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..362d192 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# Created by .ignore support plugin (hsz.mobi) +# phpstorm project files +.idea +# netbeans project files +nbproject +# zend studio for eclipse project files +.buildpath +.project +.settings +# composer itself is not needed +composer.phar +# Mac DS_Store Files +.DS_Store \ No newline at end of file diff --git a/Selectize.php b/Selectize.php index 1fb6ae5..95b1334 100644 --- a/Selectize.php +++ b/Selectize.php @@ -1,14 +1,6 @@ options['id'])) { @@ -34,23 +40,29 @@ public function init() $this->registerEvents(); } + /** + * @inheritdoc + */ public function run() { if ($this->hasModel()) { - if (empty($this->items)) { - echo Html::activeTextInput($this->model, $this->attribute, $this->options); - } else { + if (is_array($this->items)) { echo Html::activeDropDownList($this->model, $this->attribute, $this->items, $this->options); + } else { + echo Html::activeTextInput($this->model, $this->attribute, $this->options); } } else { - if (empty($this->items)) { - echo Html::textInput($this->name, $this->value, $this->options); - } else { + if (is_array($this->items)) { echo Html::dropDownList($this->name, $this->value, $this->items, $this->options); + } else { + echo Html::textInput($this->name, $this->value, $this->options); } } } + /** + * Register asset bundles + */ public function registerAssetBundle() { if (isset($this->clientOptions['plugins']) && array_search('drag_drop', $this->clientOptions['plugins'])) { @@ -61,6 +73,9 @@ public function registerAssetBundle() SelectizeAsset::register($this->getView()); } + /** + * Register client script + */ public function registerJs() { if (!isset($this->clientOptions['create']) && empty($this->items)) { @@ -70,6 +85,9 @@ public function registerJs() $this->getView()->registerJs("jQuery('#{$this->options['id']}').selectize({$clientOptions});"); } + /** + * Register client script handles + */ public function registerEvents() { if (!empty($this->clientEvents)) {