Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ws-cv-ua committed Oct 15, 2019
1 parent 3b51112 commit b2b6442
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.* linguist-language=PHP
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,23 @@ Usage
Once the extension is installed, simply use it in your code by :

```php
<?= \wscvua\yii2tagsinput\AutoloadExample::widget(); ?>```
<?= \wscvua\yii2tagsinput\AutoloadExample::widget(); ?>
```

More configuration for plugin: [Responsive Tags Input With Autocomplete - jQuery tagsInput](https://www.jqueryscript.net/form/Tags-Input-Autocomplete.html)
[Demos](https://www.jqueryscript.net/demo/Tags-Input-Autocomplete/)

Example with autocompete
---
```php
<?= $form->field($model, 'tags')->widget(\wscvua\yiitagsinput\TagsWidget::className(), [
'jsOptions' => [
'autocomplete' => [
'source' => [
'tagtest1',
'tagtest2',
]
]
]
]); ?>
```
12 changes: 6 additions & 6 deletions TagsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

namespace wscvua\yii2tagsinput;
use yii\helpers\ArrayHelper;
use yii\helpers\BaseHtml;
use yii\jui\InputWidget;

Expand All @@ -12,25 +13,24 @@
*/
class TagsWidget extends InputWidget
{
public $jsOptions = [
public $jsOptions = [];

private $defaultJsOptions = [
'interactive' => 'true',
'placeholder' => 'Add a tag',
'delimiter' => ',',
'removeWithBackspace' => true
];

public $source = [];

public function run()
{
$id = $this->getId();
$js = $this->jsOptions;
$source = $this->source;
$js = ArrayHelper::merge($this->defaultJsOptions, $this->jsOptions);

$options = $this->options;
$name = isset($options['name']) ? $options['name'] : BaseHtml::getInputName($this->model, $this->attribute);
$value = isset($options['value']) ? $options['value'] : BaseHtml::getAttributeValue($this->model, $this->attribute);

return $this->render('index', compact('id', 'js', 'source', 'name', 'value'));
return $this->render('index', compact('id', 'js', 'name', 'value'));
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "ws-cv-ua/yii2-tagsinput",
"description": "Yii2 Widget: jQuery Tags Input",
"description": "Yii2 jQuery Tags Input",
"type": "yii2-extension",
"keywords": ["yii2","tagsinput", "tag", "tag input"],
"keywords": ["yii2","tagsinput"],
"stability": "stable",
"license": "MIT",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion views/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

\wscvua\yii2tagsinput\TagsAsset::register($this);

$jsConfig = json_encode($js);
$jsConfig = \yii\helpers\Json::encode($js);

$this->registerJs(<<<JS
$('#$id').tagsInput($jsConfig);
Expand Down

0 comments on commit b2b6442

Please sign in to comment.