Skip to content

Commit b6b27b2

Browse files
empty added
1 parent 51bc8e4 commit b6b27b2

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/TagsinputWidget.php

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22
namespace avikarsha\tagsinput;
33

4+
use yii\base\InvalidConfigException;
5+
use yii\helpers\ArrayHelper;
46
use yii\helpers\Html;
57
use yii\helpers\Json;
6-
use yii\web\View;
78
use yii\web\JsExpression;
8-
use yii\helpers\ArrayHelper;
9-
use yii\base\InvalidConfigException;
9+
use yii\web\View;
1010

1111
/**
1212
* The yii2-tagsinput is a Yii 2 wrapper for bootstrap-tagsinput with typeahead.
@@ -43,16 +43,16 @@ class TagsinputWidget extends \yii\widgets\InputWidget
4343

4444
/**
4545
* @var array dataset an object that defines a set of data that hydrates suggestions.
46-
* For TypeaheadBasic, this is a single dimensional array consisting of following settings.
47-
* For Typeahead, this is a multi-dimensional array, with each array item being an array that
46+
* For TypeaheadBasic, this is a single dimensional array consisting of following settings.
47+
* For Typeahead, this is a multi-dimensional array, with each array item being an array that
4848
* consists of the following settings.
49-
* - source: The backing data source for suggestions. Expected to be a function with the
49+
* - source: The backing data source for suggestions. Expected to be a function with the
5050
* signature `(query, syncResults, asyncResults)`. This can also be a Bloodhound instance.
5151
* If not set, this will be automatically generated based on the bloodhound specific
5252
* properties in the next section below.
5353
* - display: string the key used to access the value of the datum in the datum
5454
* object. Defaults to 'value'.
55-
* - async: boolean, lets the dataset know if async suggestions should be expected. Defaults to `true`.
55+
* - async: boolean, lets the dataset know if async suggestions should be expected. Defaults to `true`.
5656
* - limit: integer the max number of suggestions from the dataset to display for
5757
* a given query. Defaults to 5.
5858
* - templates: array the templates used to render suggestions.
@@ -76,7 +76,6 @@ class TagsinputWidget extends \yii\widgets\InputWidget
7676
*/
7777
protected $_bloodhound;
7878

79-
8079
/**
8180
* @var string the generated HashPluginOptions script
8281
*/
@@ -91,7 +90,7 @@ class TagsinputWidget extends \yii\widgets\InputWidget
9190
* @var bool whether default suggestions are enabled
9291
*/
9392
protected $_defaultSuggest = false;
94-
93+
9594
/**
9695
* @var array the bloodhound settings variables
9796
*/
@@ -104,16 +103,15 @@ class TagsinputWidget extends \yii\widgets\InputWidget
104103
'identify',
105104
'local',
106105
'prefetch',
107-
'remote'
106+
'remote',
108107
];
109108

110109
/**
111110
* @inheritdoc
112111
*/
113112
public function run()
114113
{
115-
116-
if(isset($this->dataset)) {
114+
if (isset($this->dataset) && !empty($this->dataset)) {
117115
if (empty($this->dataset) || !is_array($this->dataset)) {
118116
throw new InvalidConfigException("You must define the 'dataset' property for Typeahead which must be an array.");
119117
}
@@ -156,12 +154,12 @@ protected function validateConfig()
156154
*/
157155
protected function hashPluginOptions($view)
158156
{
159-
if(isset($this->typeaheadOptions)){
160-
$this->clientOptions['typeaheadjs'][] = $this->typeaheadOptions;
157+
if (isset($this->typeaheadOptions) && !empty($this->typeaheadOptions)) {
158+
$this->clientOptions['typeaheadjs'][] = $this->typeaheadOptions;
161159
}
162160

163-
if(isset($this->_dataset)){
164-
$this->clientOptions['typeaheadjs'][] = $this->_dataset;
161+
if (isset($this->_dataset) && !empty($this->_dataset)) {
162+
$this->clientOptions['typeaheadjs'][] = $this->_dataset;
165163
}
166164

167165
$encOptions = empty($this->clientOptions) ? '{}' : Json::encode($this->clientOptions);
@@ -211,7 +209,7 @@ protected static function parseJsExpr($expr)
211209
{
212210
return ($expr instanceof JsExpression) ? $expr : new JsExpression($expr);
213211
}
214-
212+
215213
/**
216214
* Parses the data source array and prepares the bloodhound configuration
217215
*

0 commit comments

Comments
 (0)