vsn4ik / bootstrap-checkbox

A checkbox component based on Bootstrap framework.
https://vsn4ik.github.io/bootstrap-checkbox/
MIT License
213 stars 61 forks source link

Duplicated controls when dynamic active the checkboxes #1

Closed TheRplima closed 10 years ago

TheRplima commented 10 years ago

I'm trying to use this script in dynamic created checkboxes. If I only activate the checkboxes width the call $(':checkbox').checkboxpicker(); the checkboxes don't work. I need to call the function every time I insert a new checkbox. This fix the problem, but now the checkboxes that already exist are duplicated.

Did this to solve the problem.

var Checkboxpicker = function(element, options) { this.element = element;

            /** My fix **/
    if (!$(element).is(':visible')){return;}
    /** end **/
    this.$element = $(element).hide();

    this.options = $.extend({}, $.fn.checkboxpicker.defaults, options, this.$element.data());

    // .btn-group-justified works with <label> elements as the <button> doesn't pick up the styles
    this.$buttons = $('<label></label><label></label>').addClass('btn').click(this.clicked.bind(this));

    this.$off = this.$buttons.eq(0).html(this.options.offLabel);
    this.$on = this.$buttons.eq(1).html(this.options.onLabel);

    this.$group = $('<div class="btn-group"></div>')
        .append(this.$buttons)
        .keydown(this.keydown.bind(this))
        .insertAfter(element);

    this.init();
};

vsn4ik commented 10 years ago

Thanks!