From 5ccdca1703fadacd17ae914b382ebea12ad2af35 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 1 Jan 2015 09:54:18 -0500 Subject: [PATCH] Fixes #6672: `yii\bootstrap\Dropdown` should register client event handlers --- extensions/bootstrap/CHANGELOG.md | 2 +- extensions/bootstrap/Dropdown.php | 1 + extensions/bootstrap/Widget.php | 12 +++++++++++- extensions/jui/Widget.php | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/extensions/bootstrap/CHANGELOG.md b/extensions/bootstrap/CHANGELOG.md index c1e11d6..33f1f65 100644 --- a/extensions/bootstrap/CHANGELOG.md +++ b/extensions/bootstrap/CHANGELOG.md @@ -4,7 +4,7 @@ Yii Framework 2 bootstrap extension Change Log 2.0.2 under development ----------------------- -- no changes in this release. +- Bug #6672: `yii\bootstrap\Dropdown` should register client event handlers (qiangxue) 2.0.1 December 07, 2014 diff --git a/extensions/bootstrap/Dropdown.php b/extensions/bootstrap/Dropdown.php index 166b367..a4ad43b 100644 --- a/extensions/bootstrap/Dropdown.php +++ b/extensions/bootstrap/Dropdown.php @@ -60,6 +60,7 @@ class Dropdown extends Widget { echo $this->renderItems($this->items, $this->options); BootstrapPluginAsset::register($this->getView()); + $this->registerClientEvents(); } /** diff --git a/extensions/bootstrap/Widget.php b/extensions/bootstrap/Widget.php index 6e6bc85..641f640 100644 --- a/extensions/bootstrap/Widget.php +++ b/extensions/bootstrap/Widget.php @@ -71,12 +71,22 @@ class Widget extends \yii\base\Widget $view->registerJs($js); } + $this->registerClientEvents(); + } + + /** + * Registers JS event handlers that are listed in [[clientEvents]]. + * @since 2.0.2 + */ + protected function registerClientEvents() + { if (!empty($this->clientEvents)) { + $id = $this->options['id']; $js = []; foreach ($this->clientEvents as $event => $handler) { $js[] = "jQuery('#$id').on('$event', $handler);"; } - $view->registerJs(implode("\n", $js)); + $this->getView()->registerJs(implode("\n", $js)); } } } diff --git a/extensions/jui/Widget.php b/extensions/jui/Widget.php index 0676db6..458d5c2 100644 --- a/extensions/jui/Widget.php +++ b/extensions/jui/Widget.php @@ -48,7 +48,7 @@ class Widget extends \yii\base\Widget public $clientEvents = []; /** - * @var array event names mapped to what should be specified in .on( + * @var array event names mapped to what should be specified in `.on()`. * If empty, it is assumed that event passed to clientEvents is prefixed with widget name. */ protected $clientEventMap = [];