Home > Uncategorized > Bootstrap Validator with Multiple Checkboxes

Workaround:

    // Checkbox validation
    $form.on('validate.bs.validator', function(e) {
        $(this).find('input[type=checkbox]').each(function() {
            validate_checkbox($(this).attr('name'));
        });
    });
    $('.form-group').on('click','input:checkbox',function(){
        validate_checkbox($(this).attr('name'));
    });
    function validate_checkbox(name) {
        if ($('input[name="' + name + '"]:checked').length < 1){
            $('input[name="' + name + '"]').prop('required', true);
        } else {
            $('input[name="' + name + '"]').prop('required', false);
        }
    }

Reference:
https://github.com/1000hz/bootstrap-validator/issues/201
(Comments from rikbamo on Aug 31 2016)



Flag Counter