jiku / meteor-bootstrap-toggle

Wraps Bootstrap Toggle CDN for Meteor.
2 stars 2 forks source link

Timing issue? #1

Open datanotion opened 9 years ago

datanotion commented 9 years ago

We just replaced our old toggle package with this one and it's been working great - thanks! But we have noticed that every now and then the toggle remains a checkbox, but refreshing the page makes it work again. Could it be a timing issue where the javascript files aren't being loaded in the same order each time?

williamledoux commented 9 years ago

I am having the same problem here.

I think that the package will find every toggle on the page at load and transform them:

    $(function() {
        $('input[type=checkbox][data-toggle^=toggle]').bootstrapToggle()
    })

But if the templates are not rendered yet at this moment, the input will not be transformed. I think that a better approach would be to provide a handlebar helper that would call bootstrapToggle upon creation. Something like this:

    {{> BootstrapToggle options=toggle_options }}
williamledoux commented 9 years ago

I tried and it works for my use. https://atmospherejs.com/williamledoux/bootstrap-toggle

robertclarkson commented 7 years ago

Using this with aldeed:autoform and had same issue, found i could add bit of a hacky after render function on my template:

Template.afFormGroup_toggle.rendered = function() {
  $('input[type=checkbox][data-toggle^=toggle]').bootstrapToggle();
}