在焦点/键上禁用 Yii 验证错误消息 - Yii2 [英] Disable Yii Validation Error Message on focus / key up - Yii2

查看:27
本文介绍了在焦点/键上禁用 Yii 验证错误消息 - Yii2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,错误消息出现在 keyuppressing 提交按钮之后(如果该特定属性存在任何错误).这是好的.工作得很好.

As default, error message coming on keyup and after pressing submit button in form (If any error exist for that particular attribute). Which Is Ok. Working perfectly fine.

但是,是否可以在 key updisable 错误消息?意味着,错误消息(如果有)应该只在按下提交按钮时出现.

But, Is it possible to disable error message on key up? Means, error message, if any, should come only on pressing submit button.

查看

<?php $form = ActiveForm::begin([ 'id' => 'register-form']); ?>
    <?= $form->field($model, 'first_name',['inputOptions' => ['class' => 'form-control fname','placeholder'=>'First Name']])->label(false); ?>
    .
    .
<p><?= Html::submitButton('REGISTER', ['name' => 'register-button']) ?></p>     

控制器

public function actionRegister() 
{
  $model = new Users(); // User Model
  if ($model->load(Yii::$app->request->post())) {

    // For Ajax Email Exist Validation
    if(Yii::$app->request->isAjax ) {
      Yii::$app->response->format = Response::FORMAT_JSON;
      return ActiveForm::validate($model);
    }
        .
        .
    }
}

我发现 如何禁用Yii 2 中活动形式的客户端验证消息?.

$form = ActiveForm::begin(['fieldConfig' => ['template' => '{label}{input}']]);

但是,在这个答案中.错误消息既不会出现在键上也不会出现在按下提交按钮时.要显示错误摘要,我需要使用 errorSummary($model) ?>.那么,有什么方法可以禁用 key up 错误消息并显示错误消息,因为它只在 pressing 提交按钮上显示.

But, In this answer. Error message neither coming on key up nor on pressing submit button. To show error summary, I need to use <?= $form->errorSummary($model) ?>. So, Is there any way to disable key up error message and show error message as it was showing before only on pressing submit button.

推荐答案

我在 .../widgets/ActiveForm.php 中找到.一种选择是 validateOnBlur,默认设置为 true.因此,我在表单中将其更改为 false.

I found in .../widgets/ActiveForm.php. One option was there validateOnBlur which is by default set true. So, I changed it to false in my form.

@Gamitg &@Jithin:感谢您的支持.

@Gamitg & @Jithin: Thanks For Your Kind Support.

<?php $form = ActiveForm::begin([ 'id' => 'register-form','validateOnBlur' => false]); ?>

现在,一切正常.

这篇关于在焦点/键上禁用 Yii 验证错误消息 - Yii2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆