I had written a question in which the answer DID satisfy the business requirement until they changed their minds.
Uncheck checkbox if checked with jquery
This code worked awesome
$('input[type="checkbox"]').on('change', function () {
$(this).closest('tr').find('input[type="checkbox"]').not(this).prop('checked', false);
});
This code above DID satisfy the business at the time.
- Must only allow for 1 of the 3 boxes to be checked. Out, Yes, No
- Must allow for a second click on a checkbox to uncheck it so that NO checkboxes are selected.
As mentioned the above code worked great for the requirement!
HOWEVER, it is now said that OUT is separate from YES and NO
<table>
<tr>
<td>
<input id="GridView1__ctl2_chkOut" type="checkbox" name="GridView1:_ctl2:chkOut" checked="checked">
</td>
<td>
<input id="GridView1__ctl2_chkYes2" type="checkbox" name="GridView1:_ctl2:chkYes2">
</td>
<td>
<input id="GridView1__ctl2_chkNo2" type="checkbox" name="GridView1:_ctl2:chkNo2">
</td>
</tr>
</table>
So of the 3 checkboxes rules are
- Still can uncheck a box if selected.
- Out (first checkbox) is independent of 2nd and 3rd YES and NO
- Can Check 1st box and 2nd box , OR check 2nd box and 3rd box
So now when I look at this jquery
$('input[type="checkbox"]').on('change', function () {
// if checkbox equals ^Out ... Do allow for it to be checked if
//the yes or no is checked , and if checked, toggle to unchecked if clicked on
$(this).closest('tr').find('input[type="checkbox"]').not(this).prop('checked', false);
});
Seems that the logic can now get complicated with the fact of not simply being able to just look at closest checkbox in next tr tag..
Aucun commentaire:
Enregistrer un commentaire