title: Yii2: Conditional Validator always returns required
body: <p>I am trying to use Yii2's conditional validator as given in the guide like:</p>
  
  <p>Model code</p>
  
  <pre><code>public function rules()
  {
     // $discharged = function($model) { return $this-&gt;discharged == 1; };
      return [
          [[ 'admission_date','discharge_date', 'doctor_appointment_date', 'operation_date'], 'safe'],
          [[ 'package','tpa_name', 'discharged', 'bed_type', 'room_category', 'ref_doctor', 'consultant_doctor', 'operation_name'], 'integer'],
          [['advance_amount', 'operation_charges'], 'number'],
          [['patient_name', 'ref_doctor_other'], 'string', 'max' =&gt; 50],
          [['general_regn_no', 'ipd_patient_id'], 'string', 'max' =&gt; 20],
          [['admission_date', 'discharge_date', 'doctor_appointment_date', 'operation_date'],'default','value'=&gt;null],
          ['ipd_patient_id', 'unique'],
  
          [['bed_type','admission_date','room_category'],'required'],
  
          ['discharge_date', 'required', 'when' =&gt; function($model) {
              return $model-&gt;discharged == 1;
          }],
  
  
      ];
  }
  </code></pre>
  
  <p>and in my Controller like:</p>
  
  <pre><code>public function actionCreate()
      {
          $model = new PatientDetail();     
  
          if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;save()) {
              return $this-&gt;redirect(['view', 'id' =&gt; $model-&gt;id]);
          } else {
              return $this-&gt;render('create', [
                  'model' =&gt; $model,
              ]);
          }
      }
  </code></pre>
  
  <p>But whether I select or not the discharged field which is a checkbox field, the discharge date alwasys returns as required.</p>
  
  <p>What I am doing wrong here?</p>