My _form.php
<?php
/* @var $this BusinessItemsController */
/* @var $model BusinessItems */
/* @var $form BSActiveForm */
?>
<?php $form=$this->beginWidget('bootstrap.widgets.BsActiveForm', array(
'id'=>'business-items-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
),
)); ?>
<p class="help-block">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<?php //echo $form->textFieldControlGroup($model,'items_id'); ?>
<div class="gap-small"> </div>
<?php echo $form->labelEx($model,'items_id'); ?>
<?php
$this->widget('ext.select2.ESelect2',array(
'name'=>'BusinessItems[items_id]',
'data'=>CHtml::listData(Items::model()->findAll(), 'id', 'item_name'), //the whole available list
'htmlOptions'=>array(
'placeholder'=>' search Item name?',
//'options'=>$options, //the selected values
// 'multiple'=>'multiple',
'style'=>'width:530px',
),
));
?>
<div class="gap-small"> </div>
<div class="row">
<div class="col-md-7">
<?php $roles=Rights::getAssignedRoles(Yii::app()->User->Id);
foreach($roles as $role)
{
if ($role->name=='Admin')
{
echo $form->labelEx($model,'business_id');
$this->widget('ext.select2.ESelect2',array(
'name'=>'BusinessItems[business_id]',
'data'=>CHtml::listData(Business::model()->findAll(), 'id', 'business_name'), //the whole available list
'htmlOptions'=>array(
'placeholder'=>' search Business name?',
//'options'=>$options, //the selected values
//'multiple'=>'multiple',
'style'=>'width:530px',
),
));
echo $form->textFieldControlGroup($model,'isdeleted');
}
}
?>
<?php echo $form->textFieldControlGroup($model,'item_price',array('maxlength'=>60)); ?> </div>
</div>
<?php // echo $form->textFieldControlGroup($model,'image',array('maxlength'=>45)); ?>
<div class="col-md-3">
<?php // echo $form->labelEx($model,'image'); ?>
<?php echo BsHtml::activeFileField($model, 'image'); ?> <!-- // by this we can upload image-->
<?php echo $form->error($model,'image'); ?>
</div>
<div class="gap-small"> </div></br>
<?php if($model->isNewRecord!='1'){ ?>
<div class="row">
<?php echo CHtml::image(Yii::app()->request->baseUrl.'/img/'.$model->image,"image",array('width' => 250, 'height' => 250,)); ?> <!-- Image shown here if page is update page-->
<?php }
?>
</div>
<div class="gap-small"> </div>
<?php echo BsHtml::submitButton('Submit', array('color' => BsHtml::BUTTON_COLOR_PRIMARY)); ?>
<?php $this->endWidget(); ?>
It works on create, but on update, I manually type again in the dropdown.