Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to refresh a bootstrap 3.0 multiselect control. On refresh, I want to reset the checkboxes to its previous state when the partial view was first rendered

How can I achieve that?

I need to find out is there any way to achieve this through multiselect bootstrap js functions?

I tried following approach using jquery but didn't get success.

Maintained hidden field for storing selected checkbox values once view was rendered.

On Reset button click:

2.1 Uncheck all checkboxes.
2.2 Check only those checkboxes whose value I got from hidden field.


JavaScript
j('#btnReset11').click(function () {            
        j("#divErrorMessage ul li").not(':first').remove();
        j("#divErrorMessage").hide();
        j("#divSuccessMessage").hide();

        j("#includeSelectAllOption").find("option").removeAttr("selected");
        j("#chkRoles ul li").removeClass("active");
        j("#chkRoles .btn-group").find("button").removeAttr('title');
        j("#chkRoles .btn-group").find("button").text('Select');

       var value = j("#selectedCheckboxes").val();
        valueItems = value.split(", ");
        for (var i = 0; i < valueItems.length; i++) {
            j('#' + valueItems[i]).attr('selected', 'selected');
            j("#chkRoles ul li input[value=" + valueItems[i] + "]").parent().parent().parent().addClass("active");
            var title = j("#chkRoles .btn-group").find("button").title;
            j("#chkRoles .btn-group").find("button").removeAttr(title);
        }

        if (valueItems.length > 0) {
            j("#chkRoles .btn-group").find("button").text(valueItems.length + ' selected');
        }
        else {
            j("#chkRoles .btn-group").find("button").text('Select');
        }
    });
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900