I am trying to use Yii2\'s conditional validator as given in the guide like:
Model code
public function rules()
{
// $discharged = function($model) {
It seems that by default Yii2 will do validation in BOTH Server side and Client side. Check the example in Conditional Validation
part of Yii2 doc:
['state', 'required', 'when' => function ($model) {
return $model->country == 'USA';
}, 'whenClient' => "function (attribute, value) {
return $('#country').val() == 'USA';
}"],
you also need a 'whenClient'
code, or as @Alexandr Bordun said, to disable the client validation by 'enableClientValidation' => false
.