в контроллере обрабатываю ajax-запрос на валидацию
Код: Выделить всё
$modelRules = new Rules();
if (Yii::$app->request->isAjax && $modelRules->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
$modelRules->userId = (integer)Yii::$app->user->id;
if($modelRules->appliedTo == Rules::APPLIED_TO_SEARCH_TERMS) {
$modelRules->setScenario(Rules::APPLIED_TO_SEARCH_TERMS);
}
return ActiveForm::validate($modelRules);
}
'enableAjaxValidation' => true
и соответственно в шаблоне поля указал {error}
Код: Выделить всё
echo $form->field($modelRules, 'ruleName', [
'template' => '{label}<div class="form-controls">{input}{error}</div>'])
->label(Yii::t('api', 'Rule Name'), ['class' => 'form-label'])
->input('text', ['placeholder' => Yii::t('api', 'Enter rule name')])
->error(['class' => 'form-error-message text-danger']);
Заранее спасибо !