Commit 5ccdca17 by Qiang Xue

Fixes #6672: `yii\bootstrap\Dropdown` should register client event handlers

parent c27b2984
...@@ -4,7 +4,7 @@ Yii Framework 2 bootstrap extension Change Log ...@@ -4,7 +4,7 @@ Yii Framework 2 bootstrap extension Change Log
2.0.2 under development 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 2.0.1 December 07, 2014
......
...@@ -60,6 +60,7 @@ class Dropdown extends Widget ...@@ -60,6 +60,7 @@ class Dropdown extends Widget
{ {
echo $this->renderItems($this->items, $this->options); echo $this->renderItems($this->items, $this->options);
BootstrapPluginAsset::register($this->getView()); BootstrapPluginAsset::register($this->getView());
$this->registerClientEvents();
} }
/** /**
......
...@@ -71,12 +71,22 @@ class Widget extends \yii\base\Widget ...@@ -71,12 +71,22 @@ class Widget extends \yii\base\Widget
$view->registerJs($js); $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)) { if (!empty($this->clientEvents)) {
$id = $this->options['id'];
$js = []; $js = [];
foreach ($this->clientEvents as $event => $handler) { foreach ($this->clientEvents as $event => $handler) {
$js[] = "jQuery('#$id').on('$event', $handler);"; $js[] = "jQuery('#$id').on('$event', $handler);";
} }
$view->registerJs(implode("\n", $js)); $this->getView()->registerJs(implode("\n", $js));
} }
} }
} }
...@@ -48,7 +48,7 @@ class Widget extends \yii\base\Widget ...@@ -48,7 +48,7 @@ class Widget extends \yii\base\Widget
public $clientEvents = []; 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. * If empty, it is assumed that event passed to clientEvents is prefixed with widget name.
*/ */
protected $clientEventMap = []; protected $clientEventMap = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment