是否可以在 yii2 客户端/ajax 验证中比较我下面表单中的开始和结束时间。
我的视图文件代码如下:
<?php foreach ($model->weekDaysList as $index => $value) : ?>
<div class="row">
<div class="col-sm-1">
</div>
<div class="col-sm-2">
<?= $form->field($model, "[$index]td_day")->checkbox(['label' => $value]) ?>
</div>
<div class="col-sm-3">
<?= $form->field($model, "[$index]td_from") ?>
</div>
<div class="col-sm-3">
<?= $form->field($model, "[$index]td_to") ?>
</div>
</div>
<?php endforeach; ?>
控制器代码:
public function actionSchedule()
{
$model = new TimetableDetails();
$model->scenario = 'MultiSchedule';
$model->attributes = Yii::$app->request->get('sd');
if ($model->load(Yii::$app->request->post())) {
if (Yii::$app->request->isAjax) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return \yii\widgets\ActiveForm::validate($model);
}
}
if (Yii::$app->request->isAjax) {
return $this->renderAjax('schedule', [
'model' => $model,
]);
} else {
return $this->render('schedule', [
'model' => $model,
]);
}
}