[SOLVED] YiiWheels TypeAhead widget

I want to use the TypeAhead.js widget from YiiWheels with a related model.

I have it working like this in my form:




    	$engine = new Bloodhound([

        	'name' => 'familiesEngine',

        	'clientOptions' => [

            	'datumTokenizer' => new \yii\web\JsExpression("Bloodhound.tokenizers.obj.whitespace('name')"),

            	'queryTokenizer' => new \yii\web\JsExpression("Bloodhound.tokenizers.whitespace"),

            	'remote' => [

                	'url' => Url::to(['family/autocomplete', 'query'=>'QRY']),

                	'wildcard' => 'QRY'

            	]

        	]

    	]);


    	echo $form->field($model, 'FamilyID')->widget( 

        	TypeAhead::className(), 

        	[

            	'options' => [

                	'class' => 'form-control',

                	'close' => "js:console.log(\'great\')",

            	], 

            	'engines' => [ $engine ], 

            	'clientOptions' => [ 

                	'highlight' => true, 

                	'minLength' => 1 

            	], 

            	'dataSets' => [ 

                	[ 

                    	'name' => 'families',

                    	'displayKey' => 'value', 

                    	'source' => $engine->getAdapterScript() 

                	] 

            	],

        	] 

    	);



The json string being returned by Bloodhound is :




[{"ID":"2","value":"Fabaceae"}]

I don’t know how to make it display the value “Fabaceae” but have it store the ID “2”.

Most grateful for some hints / help

I found here that they updated the widget to include the ‘clientEvents’ option.

I see in my distribution, however, that I do not have the latest code, and when I run "composer update" I get the following error message:




Loading composer repositories with package information

Updating dependencies (including require-dev)

Your requirements could not be resolved to an installable set of packages.


  Problem 1

	- Conclusion: remove bower-asset/typeahead.js v0.10.5

	- yiisoft/yii2-gii 2.0.4 requires bower-asset/typeahead.js 0.10.* -> satisfiable by bower-asset/typeahead.js[v0.10.5].

	- yiisoft/yii2-gii 2.0.4 requires bower-asset/typeahead.js 0.10.* -> satisfiable by bower-asset/typeahead.js[v0.10.5].

	- yiisoft/yii2-gii 2.0.3 requires bower-asset/typeahead.js 0.10.* -> satisfiable by bower-asset/typeahead.js[v0.10.5].

	- yiisoft/yii2-gii 2.0.2 requires bower-asset/typeahead.js 0.10.* -> satisfiable by bower-asset/typeahead.js[v0.10.5].

	- yiisoft/yii2-gii 2.0.1 requires bower-asset/typeahead.js 0.10.* -> satisfiable by bower-asset/typeahead.js[v0.10.5].

	- yiisoft/yii2-gii 2.0.0 requires bower-asset/typeahead.js 0.10.* -> satisfiable by bower-asset/typeahead.js[v0.10.5].

	- Conclusion: don't install bower-asset/typeahead.js v0.10.5|keep bower-asset/typeahead.js v0.10.5

	- Installation request for yiisoft/yii2-gii * -> satisfiable by yiisoft/yii2-gii[2.0.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4].



my composer.json file:




...

	"require": {

    	"php": ">=5.4.0",

    	"yiisoft/yii2": ">=2.0.4",

    	"yiisoft/yii2-bootstrap": "*",

    	"yiisoft/yii2-swiftmailer": "*",

		"2amigos/yii2-type-ahead-widget": "~1.0"

	},

...



anybody see what I can do to fix this error and get the latest update ?

I updated the source code manually to the latest version and I now have "clientEvents" working:




'clientEvents' => [

                	'typeahead:selected' => 'function( obj, datum, name ) { $("#plant-familyid").val(datum.ID); console.log(datum.ID);}',

            	],



only thing left is displaying the text in the field instead of the ID…

plodding on…

got it working by using the related model as the input field…