Questions About Typeahead

dear community,

I’m starting to work with yiibooster. I wanted to use type-a-head and is running me perfect, but I have a problem. I want to show the name, but save the ID, how can I do this?

What I have is this:

Controller


$sqlcomunas = Yii::app()->db->createCommand('select COMUNA_NOMBRE from comuna')->queryAll();

$comunas = array();

for($i = 0; $i < sizeof($sqlcomunas); $i++){

   $comunas[] = $sqlcomunas[$i]["COMUNA_NOMBRE"];

}

view create


<?php $comunas; ?>

<?php echo $this->renderPartial('_form', array('model'=>$model, 'comunas'=>$comunas)); ?>

view _form


<?php

$this->widget(

    'bootstrap.widgets.TbTypeahead',

    array(

        'name' => 'demo-typeahead',

        'options' => array(

            'source' => $comunas,

            'items' => 4,

            'matcher' => <<<ENDL

    js:function(item) {

    return ~item.toUpperCase().indexOf(this.query.toUpperCase());

}

ENDL

        ),

    )

);

?>

Best regards

Haven’t used booster, but seems like it has some useful options like valueAttribute and displayAttribute:

http://www.yiiframework.com/forum/index.php/topic/36258-yiibooster/page__st__100

Check the docs.

Orey, thank you very much. The extension you recommended, works perfect. Even YiiBooster brings built :S

Best regards!