From 4dcbe83aa6d2ee1179a693e217ce9bbee1286d9b Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 1 Feb 2015 22:46:16 -0500 Subject: [PATCH] Fixes #6361: Added `validateAttribute()` to `yii.activeForm.js` to support manually triggering data validation of an input --- framework/CHANGELOG.md | 1 + framework/assets/yii.activeForm.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 684d9104c1c..37c7528b19f 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -12,6 +12,7 @@ Yii Framework 2 Change Log - Bug #7074: `yii\data\ArrayDataProvider` did not correctly handle the case `Pagination::pageSize = 0` (kirsenn, qiangxue) - Enh #5663: Added support for using `data-params` to specify additional form data to be submitted via the `data-method` approach (usualdesigner, qiangxue) - Enh #6106: Added ability to specify `encode` for each item of `yii\widgets\Breadcrumbs` (samdark, aleksanderd) +- Enh #6361: Added `validateAttribute()` to `yii.activeForm.js` to support manually triggering data validation of an input (Alex-Code, qiang) - Enh #6493: Added support for the `Access-Control-Expose-Headers` header by `yii\filters\Cors` (usualdesigner) - Enh #6697: Added `yii\helpers\Url::current()` method that allows adding or removing parameters from current URL (samdark, callmez) - Enh #6852: Added `yii\helpers\BaseHtmlPurifier::helpers()` in order to be able to configure `HtmlPurifier` helper globally via subclassing (Alex-Code) diff --git a/framework/assets/yii.activeForm.js b/framework/assets/yii.activeForm.js index 37a8bd81544..a72a05e6a28 100644 --- a/framework/assets/yii.activeForm.js +++ b/framework/assets/yii.activeForm.js @@ -227,6 +227,14 @@ return attribute; }, + // manually trigger the validation of the attribute with the specified ID + validateAttribute: function (id) { + var attribute = methods.find(id); + if (attribute != undefined) { + validateAttribute($(this), attribute, true); + } + }, + // find an attribute config based on the specified attribute ID find: function (id) { var attributes = $(this).data('yiiActiveForm').attributes, @@ -251,6 +259,7 @@ return this.data('yiiActiveForm'); }, + // validate all applicable inputs in the form validate: function () { var $form = $(this), data = $form.data('yiiActiveForm'), @@ -413,9 +422,6 @@ } }); } - $input.on('forceValidate.yiiActiveForm', function() { - validateAttribute($form, attribute, true); - }); }; var unwatchAttribute = function ($form, attribute) {