viter
(Chekhiv)
August 13, 2010, 6:43am
1
Hello.
Please help me to add CAutoComplete widget to CActivForm widget.
I have this code in my view file:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'vvid-form',
'enableAjaxValidation'=>true,
)); ?>
<?php echo $form->dropDownList($model,'predmet', $predmety, array('empty' => ''));?>
<?php $this->widget('CAutoComplete',
array(
'model'=>$model,
'name'=>'username',
.
.
.
.
));
?>
.
.
.
<?php $this->endWidget();?>
So form item with name ‘predmet’ is part of a $form and ‘username’ is not. How can I make ‘username’ part of $form?
Thanks.
viter
(Chekhiv)
August 15, 2010, 8:55pm
2
Nobody is going to help me?
mdomba
(Maurizio Domba Cerin)
August 16, 2010, 7:26am
3
I don’t understand exactly your question - How can I make ‘username’ part of $form?
you mean part of $model ?
Take alook at the CAutoComplete cookbook - http://www.yiiframework.com/doc/cookbook/25/
so you get the idea behind the CAutoComplete
viter
(Chekhiv)
August 16, 2010, 8:58am
4
Let me explain what I need.
I have a form created with this code:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'vvid-form',
'enableAjaxValidation'=>true,
));
This form must have two elements: dropdown list with name ‘predmet’ and text field with name ‘username’.
I include dropdown list into the form with this code:
<?php echo $form->dropDownList($model,'predmet', $predmety, array('empty' => ''));?>
Note $form-> that I use to include ‘predmet’ into my form.
The question is how to properly include into the form my textfield which is autocomplete widget.
Where $form-> must be in this code?
<?php $this->widget('CAutoComplete',
array(
'model'=>$model,
'name'=>'username',
.
.
.
.
));
?>
zaccaria
(Matteo Falsitta)
August 16, 2010, 9:21am
5
Simply don’t use $form, leave $this->widtget as it is.
viter
(Chekhiv)
August 16, 2010, 10:21am
6
But I will not be able to use validation. Or will I?
mdomba
(Maurizio Domba Cerin)
August 16, 2010, 10:26am
7
to use your thinking… validation is based on $model not on $form so as long as username is a property of the model it will be validated…
CAutoComplete is a widget and is used that way… it’s not part of the CActiveForm…
viter
(Chekhiv)
August 16, 2010, 10:42am
8
mdomba:
to use your thinking… validation is based on $model not on $form so as long as username is a property of the model it will be validated…
CAutoComplete is a widget and is used that way… it’s not part of the CActiveForm…
Yes, mdomba, you are right. Everything works Ok.
Tank you.
viter
(Chekhiv)
August 16, 2010, 11:01am
9
I solved my problem and here I want to make a little hint for those who want to use CAutoComplete widget within CActiveForm widget.
It’s very important to specify the right name property for your CAutocomplete widget. For example if your input name is ‘username’ like in my case, then instead of
'name'=>'username'
you have to write
'name'=>CHtml::activeName($model, 'username')