日、月、年の3つのドロップダウンがあります。必要な条件を適用したとき、yii2バリデーションは3つのフィールドすべてについて個別のエラーを表示します。しかし、 "dob is required"のような3つのフィールドに対して単一のエラーメッセージを表示したい。Yii2: - 3つのフィールドに1つのエラーメッセージが必要です
ビューファイル:
<?= $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'
]
私に個別にすべての3つのドロップダウンのためのエラーメッセージを示すこのコード。しかし、私はdobのための単一のエラーメッセージをしたい: "dobが必要です"。
は、私は私の質問を更新しました**モデル**と**ビュー** –
のコードを示し – garima