-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
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
data-toggle="button" initial active state #11535
Comments
👍 +1 having the same issue |
Here's a quick coffeescript hack for those who need it: class window.BsHack
@fix_btn_toggle: ->
$('[data-toggle="buttons"]').each (i, grp) ->
$(grp).children('label.btn').each (i, btn) ->
btn = $(btn)
btn.addClass('active') if btn.children('input').first().attr('checked')=='checked' |
At a minimum, please provide us a JS function which will set the correct button state across the page, which we can call at page load time. |
you should be setting this in your template… same place you are setting but for some reason if you can't access your template… just include this: $(function () {
// you may want to add an additional check to make sure that the parent is the element you expect it to be
$('[checked="checked"]').parent().addClass('active')
}) |
Why not add this to the library though? |
One possible reason is that I don't think there's a non-super-hacky way (at least without overhauling the plugin) to make that also work for elements added to the DOM after the initial page load, which would be a confusing/annoying inconsistency. |
Duplicate of #8919. |
Using data-toggle="buttons" doesn't set the initial active state of the radio/checkbox buttons if they are already checked.
In the following example, the first button should get a class of active when the widget is initialized, but it does not.
The text was updated successfully, but these errors were encountered: