【发布时间】:2014-04-05 18:03:48
【问题描述】:
嗨,我在 CGridView 中使用 CCheckBoxColumn。我想在提交表单之前检查至少应选择一个复选框值。如何为此编写规则。
以下是代码。 查看.php
'class' => 'CCheckBoxColumn', 'selectableRows' => 2,
'checkBoxHtmlOptions' => array(
'name' => 'custids[]',
'value'=>'CHtml::checkBox("cid[]",null,array("value"=>$data->customer_id,
"id"=>"cid_".$data-customer_id
))',
'type'=>'raw',
),
在模块中
public function rules() { // NOTE: you should only define rules for
those attributes that // will receive user inputs. return array( ...
.... array('custids', 'CheckSelected' ), ... }
public function CheckSelected($attribute,$params ) {
if(count($this->custids) == 0)
$this->addError($attribute,'Please select the cust ids'); }
如何在客户端验证此复选框[]。
我已经尝试过 Validate Or Limit Number Of Checkboxes Selected In Ccheckboxcolumn 链接中提到的示例。
【问题讨论】:
标签: javascript php validation yii