默認情況下,出現錯誤消息keyup
和pressing
在窗體中提交按鈕(如果該特定屬性存在任何錯誤)。哪個好。工作得很好。在焦點/鍵上禁用Yii驗證錯誤消息 - Yii2
但是,有沒有可能disable
錯誤消息key up
?手段,錯誤信息,如果有的話,只應按下提交按鈕。
查看
<?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);
}
.
.
}
}
我發現How to disable client side validation messages of active form in Yii 2?。
$form = ActiveForm::begin(['fieldConfig' => ['template' => '{label}{input}']]);
但是,在這個答案。錯誤信息既沒有出現在鍵上,也沒有按下提交按鈕。要顯示錯誤摘要,我需要使用<?= $form->errorSummary($model) ?>
。那麼,有什麼辦法可以禁用key up
錯誤信息並顯示錯誤信息,因爲它僅在pressing
提交按鈕之前顯示。
嘗試在活動窗體屬性中使用「validateOnChange」=> false。 – GAMITG
謝謝@GAMITG:tlast我明白了。並且,也發佈了以下答案。 –