From 25b117851567d07c4920b07c89a8f1198d9adede Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Thu, 3 Dec 2015 16:01:11 +0000 Subject: [PATCH] Implemented data-form support. --- framework/CHANGELOG.md | 1 + framework/assets/yii.js | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 6536c63..5edc959 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -56,6 +56,7 @@ Yii Framework 2 Change Log - Enh #10061: `yii\helpers\BaseInflector::transliterate()` is now public. Introduced different levels of transliteration strictness (silverfire) - Enh #10118: Allow easy extension of slug generation in `yii\behaviors\SluggableBehavior` (cebe, hesna) - Enh: Added last resort measure for `FileHelper::removeDirectory()` fail to unlink symlinks under Windows (samdark) +- Enh: #9893: Added support for data-form attribute so links can target specific forms (SamMousa) - Chg #9369: `Yii::$app->user->can()` now returns `false` instead of erroring in case `authManager` component is not configured (creocoder) - Chg #9411: `DetailView` now automatically sets container tag ID in case it's not specified (samdark) - Chg #9953: `TimestampBehavior::getValue()` changed to make value processing consistent with `AttributeBehavior::getValue()` (silverfire) diff --git a/framework/assets/yii.js b/framework/assets/yii.js index ccf1c96..8fdf784 100644 --- a/framework/assets/yii.js +++ b/framework/assets/yii.js @@ -144,8 +144,8 @@ yii = (function ($) { * @param $e the jQuery representation of the element */ handleAction: function ($e, event) { - var method = $e.data('method'), - $form = $e.closest('form'), + var $form = $e.attr('data-form') ? $('#' + $e.attr('data-form')) : $e.closest('form'), + method = !$e.data('method') && $form ? $form.attr('method') : $e.data('method'), action = $e.attr('href'), params = $e.data('params'), pjax = $e.data('pjax'), @@ -322,9 +322,10 @@ yii = (function ($) { var handler = function (event) { var $this = $(this), method = $this.data('method'), - message = $this.data('confirm'); + message = $this.data('confirm'), + form = $this.data('form'); - if (method === undefined && message === undefined) { + if (method === undefined && message === undefined && form === undefined) { return true; }