mercredi 1 juillet 2020

when click child checkbox Parent checkbox not selected

var permission_template =
    '<label for="selectAll%class_name%"class="m-checkbox"><input 
type = "checkbox"
class = "allPermissionsClass"
name = "permission[]"
id = "selectAll%class_name%"
value = "%id%" > % name % < span > < /span></label > '

var subpermission_template =
    '<div class="m-checkbox-list m--margin-top-10 m--padding-left-30"><label for="perm%id%"class="m- 
checkbox "><input id="
perm % id % "type="
checkbox "class=" % class_name %
    allPermissionsClass "name="
permission[]
"value=" % id % ">%name%<span></span></label></div>'

function cvalue(ID) {
    $("#cvalue").val(ID);
    $(".allPermissionsClass").prop("checked", false)
    $.post(url + link[6] + "?token=" + accessToken, {
        id: ID
    }, function(data) {
        checkAccessToken(data);
        console.log(data);
        // alert("Data Loaded: " + data);
        var cont = ""
        if (data["res"] == 0) {
            //window.location.reload();
            alert("Something went wrong, please try later.");
        } else {
            var ct = data['extra'];
            console.log(ct);
            var newString = "";
            ct.forEach(function(element) {
                newString = permission_template
                newString = newString.replace(/%id%/, element['id']);
                newString = newString.replace(/%id%/, element['id']);
                newString = newString.replace(/%id%/, element['id']);
                newString = newString.replace(/%name%/, element['name']);
                newString = newString.replace(/%class_name%/, element['class_name']);
                newString = newString.replace(/%class_name%/, element['class_name']);
                cont += newString

                var t = ""
                if (element["child_modules"].length != 0) {
                    element['child_modules'].forEach(function(e) {
                        if (Number(e.active_flag) === 1) {
                            t = subpermission_template
                            t = t.replace(/%id%/, e['id']);
                            t = t.replace(/%id%/, e['id']);
                            t = t.replace(/%id%/, e['id']);
                            t = t.replace(/%name%/, e['name']);
                            t = t.replace(/%class_name%/, element['class_name']);
                            t = t.replace(/%class_name%/, element['class_name']);
                            cont += t;
                            $(this).parent().find(':checkbox:checked').each(function(i) {

                                alert($(this).val());

                            });
                        }
                    });

                    $(document).on('click', "#selectAll" + element['class_name'], function() {
                        $("." + element['class_name']).prop('checked', $(this).prop('checked'));
                    });
                }


            });

            $("#allCheckboxes").append(cont);
            //check all tick 
            $(".allPermissionsClass").prop("checked", false);
            if (data['all_tick'].length != 0) {
                data['all_tick'].forEach(function(e) {
                    // $("input[name='permission\[\]']").find()
                    $("input[name='permission\[\]'][value='" + e + "']").prop("checked", true)
                });
            }
            //$("input[name='permission\[\]'][value='1']").parent().hide();
        }
    });
}

here above code used to get permission checkboxes into popup form, I couldn't select parent checkbox while clicking the child checkbox! data getting from the DB table, I don't know how to do on checking any child checkbox to check the parent checkbox. I want to mark the parent checkbox even I select one child checkbox.

Are there any solutions available!




Aucun commentaire:

Enregistrer un commentaire