1

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.

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

View

<?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>     

Controller

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);
    }
        .
        .
    }
}

I found How to disable client side validation messages of active form in Yii 2?.

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

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.

Community
  • 1
  • 1
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77

2 Answers2

3

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: Thanks For Your Kind Support.

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

Now, It's Working fine.

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
0

Add

'enableClientValidation'=>false

to your form options:

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