我启用了 clientValidation,甚至当我点击一个 textField 并将其留空时,例如 - Yii 验证 textField 和 dropDownList。
小部件:
$form=$this->beginWidget('CActiveForm', array(
'id'=>'service-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
下拉列表
$models = Countries::model()->findAll();
$list = CHtml::listData($models, 'countryname', 'countryname');
echo $form->dropDownList($model, 'country', $list, array('empty' => 'Select a country...'));
echo $form->error($model,'country');
规则()
public function rules()
{
return array(
array('name, country, postal_code, city, adress, description', 'required'),
array('name', 'unique','className'=>'Item','attributeName'=>'name','message'=>"Company already exists"),
array('postal_code', 'numerical', 'integerOnly'=>true),
array('name, country, adress, description', 'length', 'max'=>255),
array('city', 'length', 'max'=>150),
array('id, name, country, postal_code, city, adress, description, category, create_date', 'safe', 'on'=>'search'),
);
}