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

yii\bootstrap\ButtonDropdown splitButton gets same options as primary button #6720

Closed
ASlatius opened this issue Jan 1, 2015 · 4 comments
Closed

Comments

@ASlatius
Copy link
Contributor

ASlatius commented Jan 1, 2015

When rendering with 'split'=>true, the dropdown-toggle is rendered with a second button. This button gets the same options as the primary buttons.
This is getting problematic when you try and set options for JavaScript usage like 'id' and 'onclick'.

@samdark
Copy link
Member

samdark commented Jan 4, 2015

Any ideas on how to solve it?

@ASlatius
Copy link
Contributor Author

ASlatius commented Jan 4, 2015

I've currently overruled the options['id'] locally in the if ($this->split) section and removed the 'onclick' from the option array. But to be honest, I'm not sure whether that is all that needs to be changed for the second button. All JS events shoud probably be removed but I don't know the quickest way to do that.
Alternatively we can define a public $splitOptions (or something like that) that normally copies public $options but doesn't if set.
I'm willing to code it in a PR.

@yii-bot
Copy link

yii-bot commented Jan 24, 2016

Issue moved to yiisoft/yii2-bootstrap#108

@yii-bot yii-bot closed this as completed Jan 24, 2016
@ruturajmaniyar
Copy link

ruturajmaniyar commented Oct 14, 2019

You can simply change on your code and resolved this issue.
In ButtonDropDown.php line number : 109, you can find below code.

if ($this->split) {
            $options = $this->options;
            $this->options['data-toggle'] = 'dropdown';
            Html::addCssClass($this->options, ['toggle' => 'dropdown-toggle']);
            unset($options['id']);
            $splitButton = Button::widget([
                'label' => '<span class="caret"></span>',
                'encodeLabel' => false,
                'options' => $this->options,
                'view' => $this->getView(),
            ]);
        } else {
            $label .= ' <span class="caret"></span>';
            $options = $this->options;
            Html::addCssClass($options, ['toggle' => 'dropdown-toggle']);
            $options['data-toggle'] = 'dropdown';
            $splitButton = '';
        }

you can change in above code, in "ELSE" part only and solved "splitButton" option issue.

else {
            $label .= ' <span class="caret"></span>';
            $options = $this->options;
            $options['data-toggle'] = 'dropdown';
            Html::addCssClass($options, ['toggle' => 'dropdown-toggle']);
            unset($options['id']);
            $splitButton = '';
        }

Here issue is that 'data-toggle' option want to add before "html" and need to unset "$options['id']" after html is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants