sayus2884
(Joniah2884)
May 18, 2014, 2:46am
1
Hi, I’m using YiiWheel’s Select2 in my form but I can’t seem to pass the value from the widget. Can you guys help? An example would be nice. I couldn’t find answers from my searches. Here’s my code so far:
$this->widget('yiiwheels.widgets.select2.WhSelect2', array(
'id'=>'accCodeSel2',
'model'=> $model,
'attribute' => 'account_code_id',
'asDropDownList' => true,
'data' => array(
'Account Codes' => AccountCode::model()->findAll($criteria)
),
));
Maybe I’m missing something?
<?php $this->widget('yiiwheels.widgets.select2.WhSelect2', array(
'model'=>$model,
'attribute'=>'account_code_id',
'htmlOptions'=>array(
'style'=>'width:100%; min-height:22px; ',
'multiple'=>'multiple',
'placeholder'=>'Product Model',
),
'data' => CHtml::listData( AccountCode::model()->findAll(
array('order' => 'name ASC')),
'id',
'name'
),
));
?>
id is what’s saved and name is whats shown in the list
also note you can make multiple =>false to only allow one
if you save it as a string in your database (value1,value2) you will need to modify your actionupdate in your controller (you will need to explode it).
if($model->account_code_id!==array())
$model->account_code_id = explode(',', $model->account_code_id);
if you don’t it will not show all of the values in the update only the first one
keny
(Ktpacheco1)
May 21, 2014, 2:36am
3
skworden:
<?php $this->widget('yiiwheels.widgets.select2.WhSelect2', array(
'model'=>$model,
'attribute'=>'account_code_id',
'htmlOptions'=>array(
'style'=>'width:100%; min-height:22px; ',
'multiple'=>'multiple',
'placeholder'=>'Product Model',
),
'data' => CHtml::listData( AccountCode::model()->findAll(
array('order' => 'name ASC')),
'id',
'name'
),
));
?>
id is what’s saved and name is whats shown in the list
also note you can make multiple =>false to only allow one
if you save it as a string in your database (value1,value2) you will need to modify your actionupdate in your controller (you will need to explode it).
if($model->account_code_id!==array())
$model->account_code_id = explode(',', $model->account_code_id);
if you don’t it will not show all of the values in the update only the first one
How these fields are validated?
I get an error because it is required and does not send any value
Thanks