Yii2: Conditional Validator always returns required

前端 未结 5 1481
-上瘾入骨i
-上瘾入骨i 2021-02-07 17:24

I am trying to use Yii2\'s conditional validator as given in the guide like:

Model code

public function rules()
{
   // $discharged = function($model) {          


        
5条回答
  •  独厮守ぢ
    2021-02-07 17:59

    This only worked for me when using the model name (client validation).

    ['state', 'required', 'when' => function ($model) {
      return $model->country == 'USA';
    }, 'whenClient' => "function (attribute, value) {
      return $('#MODELNAMEHERE-country').val() == 'USA';
    }"]

提交回复
热议问题