Thursday, 19 July 2012

Custom validation on TreeView (atleast one child should be selected when parent is selected)


Custom validation on TreeView (Atleat one child should be selected when parent is selected)

function validate(source, arguments) {
        var flag = false;
        $("div[id $= 'tree'] input[type=checkbox]").each(function () {
            if (this.checked) {
                var notchecked = $(this).closest("table").next("div").find("input[type=checkbox]");
                //                alert("notchecked" +notchecked.length)
                if (notchecked.length > 0) {
                    //                    alert("checked");
                    var ab = $(this).closest("table").next("div").find("input[type=checkbox]:checked");
                    if (ab.length > 0) {
                        alert("done " + ab.length)
                        flag = true;
                    }
                    else {
                        //                        alert("not done " + ab.length)
                        flag = false;
                        return flag;
                    }
                }
            }
        });
        arguments.IsValid = flag;
        return arguments.IsValid;
    }
</script>

<asp:TreeView ID="tree" SelectedNodeStyle-CssClass="tezt" ShowCheckBoxes="All" runat="server">
</asp:TreeView>
<asp:CustomValidator runat="server" Display="Dynamic" ValidateEmptyText="true" ClientValidationFunction="validate"
    ID="CustomValidator31" ValidationGroup="vGStep2" ControlToValidate="tree"
    ErrorMessage="roperSelection of PG is required" Text="*" SetFocusOnError="true"></asp:CustomValidator>
<asp:Button ID="btnValidate

No comments:

Post a Comment