Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap ButtonGroup clientEvent not being assigned properly. #8028

Closed
alagodich opened this issue Apr 9, 2015 · 5 comments
Closed

Bootstrap ButtonGroup clientEvent not being assigned properly. #8028

alagodich opened this issue Apr 9, 2015 · 5 comments
Labels

Comments

@alagodich
Copy link

Hello

As stated here: http://getbootstrap.com/javascript/#dropdowns-events

All dropdown events are fired at the .dropdown-menu's parent element.

But parent container for widget is being rendered via Html::beginTag and we cannot assign any events to it with 'clientEvents' option.

        return implode("\n", [
            Html::beginTag($tag, $this->containerOptions),
@samdark
Copy link
Member

samdark commented Apr 9, 2015

What's your issue exactly? What are you trying to do? How to reproduce it?

@alagodich
Copy link
Author

I am trying to hook up show.bs.dropdown event on yii\bootstrap\ButtonDropdown widget, to have this:

$('#myDropdown').on('show.bs.dropdown', function () {
  // do something…
})

And for that i suppose to use clientEvents attribute, but when i use it like this:

return ButtonDropdown::widget([
    ...
    'clientEvents' => ['show.bs.dropdown' => 'function() {...}']
]);

It binds this event to the dropdown itself but not to the parent, so it doesn't work.

I think ButtonDropdown should attach these clientEvents to it's parent (container).

@samdark samdark added status:to be verified Needs to be reproduced and validated. ext:bootstrap labels Apr 9, 2015
@samdark
Copy link
Member

samdark commented Apr 9, 2015

Most probably. Any idea on how to fix it?

@alagodich
Copy link
Author

What if we assign id to the containerOptions, if it was not assigned, and then override registerClientEvents() method, so it will bind all events not to the widget id but to container id?
Something like this:

    protected function registerClientEvents()
    {
        if (!empty($this->clientEvents)) {
            $id = $this->containerOptions['id'];
            $js = [];
            foreach ($this->clientEvents as $event => $handler) {
                $js[] = "jQuery('#$id').on('$event', $handler);";
            }
            $this->getView()->registerJs(implode("\n", $js));
        }
    }

Or better just accept clientEvents in containerOptions additionally. And attach them to the container element.

@yii-bot
Copy link

yii-bot commented Jan 24, 2016

Issue moved to yiisoft/yii2-bootstrap#112

@yii-bot yii-bot closed this as completed Jan 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants