No way to create a link styled as a button
Closed this issue · 6 comments
Opening this topic for discussion - more info in #926
This problem was introduced after 4.01 was released, and definitely breaks existing code (the button will render as a plain link without the button styling).
I personally don't see the point in using TbButton to render a link styled as a link, but my proposed solution was to use the context
attribute for representing links and leaving self::BUTTON_LINK
to dictate what tag is rendered (a
) instead of input
or button
....
I'm surprised there aren't more people seeing this issue, as I would expect it's a pretty common usage scenario. Unless of course, I'm completely misunderstood, and trying to use it incorrectly!
Thanks guys!
see http://getbootstrap.com/css/#buttons
look at button type link
right, but in YiiBooster, there is no way to have it render as an anchor tag - which is the only tag left out...I'm looking for a link styled as a bootstrap button, not a button styled as a link. This worked fine in previous versions, and the behavior has since been changed.
Use the button classes on an <a>, <button>, or <input> element.
u can use CHtml::link and add whatever classes you want ... currently we do not have a wrapper for this widget ... maybe it is not required ... do we really require a wrapper for link?
No, I would say it is not necessarily required, but the behavior changed in this commit: 7c25829 Before that, you were able to get a link styled as a button using the TbButton Widget.
To me that means there is a break in compatibility between 4.01 and the next YiiBooster release, which, in the very least, should be documented somewhere, as it is not immediately apparent that things are broken until you actually try to click the button (using your 4.01 code), and it does nothing, instead of taking you to the link in the url
parameter.
yes it is a break in compatibility ... we are sorry for this
but: we considered it a bug in the first release that was fixed in the second one ...
we are really sorry for that
@amrbedair Thanks for the response. As far as no need to create a wrapper for a link, that's effectively what passing buttonType => BUTTON_LINK
does with this current code in place, it renders a link with NO bootstrap styling (whereas before it would at least look like the other TbButtons).
I'm still a bit confused as it seems to be contrary to the original design where BUTTON_XXXX
constants are used to dictate how the tag is rendered (button
,a
,input
, and the context
CTX_XXXX
constants are used to designate the "decoration" of the item (primary, warning...etc).
It seems that if this is how things will continue, you can probably remove the declarations of CTX_LINK and CTX_LINK_CLASS.
For anyone following, this code effectively reproduces the previous button functionality:
echo CHtml::link(
'<i class="fa fa-edit"></i> Edit Model</a>',
['model/edit', 'id' => $model->id],
['class' => 'btn btn-default btn-block']
);