From a187d47aec399fac5e0af1a8e7ded33b3c27ef38 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 16 Sep 2014 14:40:00 -0400 Subject: [PATCH] Fixes #5049: `ActiveForm::validationDelay` should be applied to user types only --- framework/CHANGELOG.md | 1 + framework/assets/yii.activeForm.js | 8 ++++---- framework/widgets/ActiveField.php | 6 +++--- framework/widgets/ActiveForm.php | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 98abe4b026..66fe83f37f 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -96,6 +96,7 @@ Yii Framework 2 Change Log - Bug #4970: `joinWith()` called by a relation was ignored by `yii\db\ActiveQuery` (stepanselyuk) - Bug #5001: `yii\rest\CreateAction`, `yii\rest\UpdateAction` and `yii\rest\DeleteAction` should throw 500 error if the model operation returns false without validation errors (qiangxue) - Bug #5039: `UniqueValidator` and `ExistValidator` did not respect query conditions added by default scope (qiangxue) +- Bug #5049: `ActiveForm::validationDelay` should be applied to user types only (qiangxue) - Bug: Fixed inconsistent return of `\yii\console\Application::runAction()` (samdark) - Bug: URL encoding for the route parameter added to `\yii\web\UrlManager` (klimov-paul) - Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue) diff --git a/framework/assets/yii.activeForm.js b/framework/assets/yii.activeForm.js index 98e2aa8933..827f075bc4 100644 --- a/framework/assets/yii.activeForm.js +++ b/framework/assets/yii.activeForm.js @@ -145,7 +145,7 @@ // whether to perform validation when the user is typing. validateOnType: false, // number of milliseconds that the validation should be delayed when a user is typing in the input field. - validationDelay: 200, + validationDelay: 500, // whether to enable AJAX-based validation. enableAjaxValidation: false, // function (attribute, value, messages), the client-side validation function. @@ -411,7 +411,7 @@ if (attribute.validateOnType) { $input.on('keyup.yiiActiveForm', function () { if (attribute.value !== getValue($form, attribute)) { - validateAttribute($form, attribute, false); + validateAttribute($form, attribute, false, attribute.valdationDelay); } }); } @@ -421,7 +421,7 @@ findInput($form, attribute).off('.yiiActiveForm'); }; - var validateAttribute = function ($form, attribute, forceValidate) { + var validateAttribute = function ($form, attribute, forceValidate, validationDelay) { var data = $form.data('yiiActiveForm'); if (forceValidate) { @@ -451,7 +451,7 @@ } }); methods.validate.call($form); - }, attribute.validationDelay); + }, validationDelay ? validationDelay : 200); }; /** diff --git a/framework/widgets/ActiveField.php b/framework/widgets/ActiveField.php index b46dd074a6..5bc62818d0 100644 --- a/framework/widgets/ActiveField.php +++ b/framework/widgets/ActiveField.php @@ -111,8 +111,8 @@ class ActiveField extends Component */ public $validateOnType; /** - * @var integer number of milliseconds that the validation should be delayed when the input field - * is changed or the user types in the field. + * @var integer number of milliseconds that the validation should be delayed when the user types in the field + * and [[validateOnType]] is set true. * If not set, it will take the value of [[ActiveForm::validationDelay]]. */ public $validationDelay; @@ -747,7 +747,7 @@ class ActiveField extends Component 'validateOnChange' => true, 'validateOnBlur' => true, 'validateOnType' => false, - 'validationDelay' => 200, + 'validationDelay' => 500, 'encodeError' => true, 'error' => '.help-block', ]); diff --git a/framework/widgets/ActiveForm.php b/framework/widgets/ActiveForm.php index a4cbc3561c..0bc1f061eb 100644 --- a/framework/widgets/ActiveForm.php +++ b/framework/widgets/ActiveForm.php @@ -131,11 +131,11 @@ class ActiveForm extends Widget */ public $validateOnType = false; /** - * @var integer number of milliseconds that the validation should be delayed when an input field - * is changed or the user types in the field. + * @var integer number of milliseconds that the validation should be delayed when the user types in the field + * and [[validateOnType]] is set true. * If [[ActiveField::validationDelay]] is set, its value will take precedence for that input field. */ - public $validationDelay = 200; + public $validationDelay = 500; /** * @var string the name of the GET parameter indicating the validation request is an AJAX request. */