我有日、月和年的三个下拉菜单。当我应用所需条件时,yii2 验证显示所有三个字段的单独错误。但是我想要三个字段的单个错误消息,例如“需要 dob”。
查看文件 :
<?= $form->field($model, "month")->dropDownList([], ['class'=>'form-control day'])->label(false);?>
<?= $form->field($model, "day")->dropDownList([], ['class'=>'form-control day'])->label(false);?>
<?= $form->field($model, "year")->dropDownList([], ['class'=>'form-control year'])->label(false);?>
模型 :
public $day;
public $month;
public $year;
[['month','day','year'], 'required', 'when' => function ($model) {
return (($model->month == "") || ($model->day == "") || ($model->year == ""));
},
'whenClient' => "function (attribute, value) {
return ($('#user-month').val() == '' || $('#user-day').val() == '' || $('#user-year').val() == '');
}",'on'=>'profile'
]
此代码分别向我显示所有三个下拉列表的错误消息。但我想要一个 dob 的错误消息:比如“dob 是必需的”。