Commit b98d116a by Antonio Ramirez

refactored to add function on `gii.js`

parent 65c740e9
...@@ -70,6 +70,15 @@ yii.gii = (function ($) { ...@@ -70,6 +70,15 @@ yii.gii = (function ($) {
}; };
return { return {
autocomplete: function (counter, data) {
var datum = new Bloodhound({
datumTokenizer: function(d){return Bloodhound.tokenizers.whitespace(d.word);},
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: data
});
datum.initialize();
jQuery('.typeahead-'+counter).typeahead(null,{displayKey: 'word', source: datum.ttAdapter()});
},
init: function () { init: function () {
initHintBlocks(); initHintBlocks();
initStickyInputs(); initStickyInputs();
......
...@@ -66,14 +66,7 @@ class ActiveField extends \yii\widgets\ActiveField ...@@ -66,14 +66,7 @@ class ActiveField extends \yii\widgets\ActiveField
foreach($data as &$item) { foreach($data as &$item) {
$item = array('word' => $item); $item = array('word' => $item);
} }
$this->form->getView()->registerJs(" $this->form->getView()->registerJs("yii.gii.autocomplete($counter, " . Json::encode($data) . ");");
var datum = new Bloodhound({
datumTokenizer: function(d){return Bloodhound.tokenizers.whitespace(d.word);},
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: " . Json::encode($data) . "
});
datum.initialize();
jQuery('.typeahead-{$counter}').typeahead(null,{displayKey: 'word', source: datum.ttAdapter()});");
return $this; return $this;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment