CJuiAutoComplete , attribute and value

i have a autocomplete field with:


$this->widget('zii.widgets.jui.CJuiAutoComplete', array(

            'attribute'=>'title',

	    'model'=>$model,

            'sourceUrl'=>'index.php?r=gettitle',

            'value'=>'a default value',

            'options'=>array(

            'minLength'=>'2'

             ),

            ));

but default value don’t appear in autocomplete filed.

if i remove attribute and use name instead of , value appear in autocomplete.

how can i have attribute and value together?

If you look at the line 83 of CJuiAutocomplete you find the response to your question




if($this->hasModel())

	echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions);

else

	echo CHtml::textField($name,$this->value,$this->htmlOptions);



That means that has priority on the model attribute…

If you wish to have a default value when the attribute is empty then use something like this:




$config = !empty($model->title)? array('model'=>$model, 'attribute'=>'title') : array('value'=>'a default value');

$this->widget('zii.widgets.jui.CJuiAutoComplete', CMap::merge( array(

            'sourceUrl'=>'index.php?r=gettitle',

            'options'=>array(

            'minLength'=>'2'

             )), $config)

            );

// totally untested



thank u but i want attribute and a default value together but it seems this is impossible.

i’m right?

Just initialize the attribute with the default value.

/Tommy