This commit is contained in:
simialbi 2022-11-30 09:17:05 +01:00
parent 238be4f85c
commit 1c8504e9f1
No known key found for this signature in database
GPG Key ID: 90C9DF26A55C2070
3 changed files with 6 additions and 5 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 bootstrap5 extension Change Log
2.0.4 under development 2.0.4 under development
----------------------- -----------------------
- Bug #58: Dropdown clientEvents did not fire because they need to be bound on parent (simialbi)
- Bug #43: Accordion widget does not set "collapsed" class on toggle button (simialbi) - Bug #43: Accordion widget does not set "collapsed" class on toggle button (simialbi)
- Enh #39: Add inline mode to `BaseHtml::checkboxList()` and `BaseHtml::radioList()` (WinterSilence) - Enh #39: Add inline mode to `BaseHtml::checkboxList()` and `BaseHtml::radioList()` (WinterSilence)
- Enh #40: Breadcrumbs refactoring (WinterSilence) - Enh #40: Breadcrumbs refactoring (WinterSilence)

View File

@ -94,7 +94,6 @@ trait BootstrapWidgetTrait
// 'popover', 'toast' and 'tooltip' plugins not activates via data attributes // 'popover', 'toast' and 'tooltip' plugins not activates via data attributes
if ( if (
$this->clientOptions !== false $this->clientOptions !== false
|| !empty($this->clientOptions)
|| in_array($name, ['popover', 'toast', 'tooltip'], true) || in_array($name, ['popover', 'toast', 'tooltip'], true)
) { ) {
$name = ucfirst($name); $name = ucfirst($name);
@ -103,20 +102,21 @@ trait BootstrapWidgetTrait
$view->registerJs("(new bootstrap.$name('#$id', $options));"); $view->registerJs("(new bootstrap.$name('#$id', $options));");
} }
$this->registerClientEvents(); $this->registerClientEvents($name);
} }
} }
/** /**
* Registers JS event handlers that are listed in [[clientEvents]]. * Registers JS event handlers that are listed in [[clientEvents]].
*/ */
protected function registerClientEvents() protected function registerClientEvents(string $name = null)
{ {
if (!empty($this->clientEvents)) { if (!empty($this->clientEvents)) {
$id = $this->options['id']; $id = $this->options['id'];
$js = []; $js = [];
$appendix = ($name === 'dropdown') ? '.parentElement' : '';
foreach ($this->clientEvents as $event => $handler) { foreach ($this->clientEvents as $event => $handler) {
$js[] = "document.getElementById('$id').addEventListener('$event', $handler);"; $js[] = "document.getElementById('$id')$appendix.addEventListener('$event', $handler);";
} }
$this->getView()->registerJs(implode("\n", $js)); $this->getView()->registerJs(implode("\n", $js));
} }

View File

@ -85,7 +85,7 @@ class Dropdown extends Widget
public function run(): string public function run(): string
{ {
BootstrapPluginAsset::register($this->getView()); BootstrapPluginAsset::register($this->getView());
$this->registerClientEvents(); $this->registerClientEvents('dropdown');
return $this->renderItems($this->items, $this->options); return $this->renderItems($this->items, $this->options);
} }