I am quiet new in Yii. I am trying to generate Dependent dropdown field using ajax I had one view file name swap.php andhaving the following code included in it
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'projects-form',
'type'=>'horizontal',
'enableAjaxValidation'=>false,
'enableClientValidation'=>true,
'htmlOptions'=>array(
'enctype'=>"multipart/form-data"
)
)); ?>
<?php echo $form->dropDownListRow($model, 'salesperson', $data,array('labelOptions'=>array('label'=>'Select Sales Person'),'empty'=>array(''=>'Choose Sales Person'), 'class'=>'span3','maxlength'=>5,
'ajax'=>array(
'type'=>'POST',
'url'=>$this->createUrl('getUsers'),
'update'=>'#SalesPersonsAssignLog_users'
)
));
?>
<div id="SalesPersonsAssignLog_users">
</div>
<?php $this->endWidget(); ?>
in the corresponding controller I had the following function
public function actionGetUsers()
{
$result = $_POST['SalesPersonsAssignLog'];
$salesPersonId = $result['salesperson'];
$model = new UsersSalesPersons;
$result = $model->getAssignedCompanies($salesPersonId);
$resultArray = array();
foreach($result as $value)
{
$id = $value->company->user_id;
$name = $value->company->user_company;
$resultArray[$id] = $name;
}
$this->renderPartial('_ajaxUsers',array('data'=>$resultArray,'model'=>$model));
}
the __ajaxUsers.php
I need to create a dropdownListRow
using TbActive form
,
<?php echo $form->dropDownListRow($model, 'users', $data,array('labelOptions'=>array('label'=>'Sales Person'),'empty'=>array(''=>'Choose Sales Person'), 'class'=>'span3','maxlength'=>5)); ?>
Got a fatal error Call to a member function dropDownListRow()
on a non-object as no TbActiveForm
include in this page, Then how can I create a dropdownListRow
on ajax call
You have to initialize $form as TbActiveForm widget and give it path to TbActiveForm file
$form = $this->beginWidget( 'ext.bootstrap.widgets.TbActiveForm', array(
'id' => 'test-form'
) );
Don't forget to end widget
$this->endWidget();