Skip to content

Commit

Permalink
update widget & README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
xjflyttp committed May 24, 2015
1 parent 1af0ed7 commit ed5043e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,45 @@ composer.json
In View
---------
```php
use xj\tagit\TagitAsset;
TagitAsset::register($this);
xj\tagit\TagitAsset::register($this);

//work with ActiveForm
$form->field($model, 'tags')->widget(\xj\tagit\Tagit::className(), [
'clientOptions' => [
'availableTags' => ['aaa', 'bbb']
//....
]
]);

//work with hidden input
echo yii\helpers\Html::hiddenInput('mytag', '', ['id' => 'myTagId']);
echo Tagit::widget([
'renderInput' => false,
'id' => 'myTagId',
'name' => 'mytag',
'value' => ['a', 'b'],
'clientOptions' => [
'availableTags' => ['aaa', 'bbb']
]
]);

//work with hidden input (input init value)
echo yii\helpers\Html::hiddenInput('mytag2', 'a,b,c,d', ['id' => 'myTagId2']);
echo Tagit::widget([
'renderInput' => false,
'id' => 'myTagId2',
'name' => 'mytag2',
'clientOptions' => [
'availableTags' => ['aaa', 'bbb']
]
]);

//auto render
echo Tagit::widget([
'id' => 'myTagId3',
'name' => 'mytag3',
'clientOptions' => [
'availableTags' => ['aaa', 'bbb']
]
]);
```
7 changes: 4 additions & 3 deletions Tagit.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ class Tagit extends InputWidget
*/
public function run()
{
TagitAsset::register($this->getView());
$this->registerScript();
if (true === $this->renderInput) {
echo $this->renderWidget();
}
$this->registerScript();
}

/**
Expand All @@ -51,10 +52,10 @@ protected function renderWidget()

protected function registerScript()
{
$id = $this->getId();
$id = $this->options['id'];
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
$js = "jQuery('#{$id}').tagit({$options})";
$js = "jQuery('#{$id}').tagit({$options});";
$this->getView()->registerJs($js);
}
}
Expand Down

0 comments on commit ed5043e

Please sign in to comment.