Javascript 客户端Yii CCheckBoxColumn验证(Java脚本)
Hi Iam在CGridView中使用CCHECKBOX列。我希望在提交表单之前至少选中一个复选框值。如何为此编写规则 下面是代码。 view.php 模内Javascript 客户端Yii CCheckBoxColumn验证(Java脚本),javascript,php,validation,yii,Javascript,Php,Validation,Yii,Hi Iam在CGridView中使用CCHECKBOX列。我希望在提交表单之前至少选中一个复选框值。如何为此编写规则 下面是代码。 view.php 模内 public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( ... .... array('custids', 'Check
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'); }
如何在客户端验证此复选框[]
我尝试了链接中提到的示例。我看不到活动表单的代码,但您始终可以在客户端选中此项,只要选中至少一个复选框,就可以让表单提交 你可以:
现在,如果这是一个空数组,您可以停止。您可以在验证客户端后添加此签入选项
$form = $this->beginWidget(
'CActiveForm',
array('id' => 'add_category_form',
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
'ajaxVar' => 'ajax',
'afterValidate' => "js: function(form, data, hasError) {
///check it there
return false;
}
"
)
)
);
这是javascript,在发送表单数据之前使用它。请提供示例代码,说明在何处以及如何使用此javascript?
var idArray = $(gridID).yiiGridView('getChecked', columnID);
// or
$.fn.yiiGridView.getSelection(gridID);
$form = $this->beginWidget(
'CActiveForm',
array('id' => 'add_category_form',
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
'ajaxVar' => 'ajax',
'afterValidate' => "js: function(form, data, hasError) {
///check it there
return false;
}
"
)
)
);