Skip to content

Commit

Permalink
Addition .gitignore and fix type of items
Browse files Browse the repository at this point in the history
  • Loading branch information
nghian committed Jan 24, 2015
1 parent a90dd7e commit c4da2b3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
48 changes: 33 additions & 15 deletions Selectize.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
<?php
/**
* Created by PhpStorm.
* User: Nghia
* Date: 10/10/2014
* Time: 6:43 AM
*/

namespace yii\selectize;


use yii\helpers\Html;
use yii\widgets\InputWidget;
use yii\helpers\Json;
use yii\jui\JuiAsset;

class Selectize extends InputWidget
{
public $items = [];
/**
* @var array
*/
public $items;
/**
* @var array
* @see https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md#options
*/
public $clientOptions;
/**
* @var array
* @see https://github.com/brianreavis/selectize.js/blob/master/docs/events.md
*/
public $clientEvents;

/**
* @inheritdoc
*/
public function init()
{
if (!isset($this->options['id'])) {
Expand All @@ -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'])) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand Down

0 comments on commit c4da2b3

Please sign in to comment.