I want to uncheck a checked checkbox when its parent checkbox is not checked ; I mean by a parent checkbox a checkbox having an id attribute value that has parent-child business logic in the database. In the layout it looks like this :
As you can see the "Départements" checkbox is the parent of the two below checkboxes "Ajout" and "Modification".
So I want to prevent checking the child checkbox , say "Ajout" , if its parent "Départements" is not checked. Here is what I did :
<c:forEach items="${hash_map_menu.value}" var="menu" varStatus="iterator">
<c:set var="indentation" value=""/>
<table class="table">
<tbody>
<c:if test="${menu.menu_bouton == 1}">
<c:forEach begin="0" end="${menu.depth - 1}">
<c:set var="indentation" value="${indentation} " />
</c:forEach>
</c:if>
<tr>
<td id="menulib_${menu.menu_id}">${indentation}${menu.menu_navigation}</td>
<td width="5%" align="center"><label><input type="checkbox" class="minimal" id="${menu.menu_id}" name="${menu.menu_id}" value="${menu.menu_id}" /></label></td>
</tr>
</tbody>
</table>
</c:forEach>
<script type="text/javascript">
$(function() {
$(":checkbox").on("ifChecked", function() {
var menu_id = $(this).attr("id");
if (isMenuChild(menu_id) == "true") { // it has a parent checkbox
var menu_parent_id = getMenuParent(menu_id);
if ( ! $("#"+menu_parent_id).prop("checked") ) {
$(this).iCheck('uncheck');
}
}
});
});
</script>
At runtime I can check a child checkbox even if its parent is not checked , and when I try to uncheck it then I cannot ! So what is wrong in my code ?
Aucun commentaire:
Enregistrer un commentaire