#StackBounty: #javascript #angularjs How to disable checkboxes if another checkbox with same id is checked

Bounty: 50

I have a table with checkbox in one of the column. When a checkbox is checked I push the row into an array.

I have tried to explain better in terms of ..real world down below

The table can have rows with duplicate id(other column of the row (flat_id) is different). The duplicate id I mentioned above is user_map_id.

When I check(click on checkbox) a row, I want other rows with same user_map_id to be disabled.

So when a row is checked I store the user_map_ids in an array. And then I do this:

ng-disabled="selectedUserMapIdArray.indexOf(flat.user_map_id) >= 0

i.e I disable the row if the user_map_id is present in the array with selected user_map_ids but this disables the one I checked too and I can’t uncheck it if I want to.

So I pushed the flat_ids in an array too and did this:

ng-disabled="selectedUserMapIdArray.indexOf(flat.user_map_id) >= 0 && selectedFlatNumArray.indexOf(flat.flat_id) < 0 "

i.e Disable row if the row’s user_map_id is present in the selectedUserMapIdArray(which stores the user_map_id) array and not present in the selectedFlatNumArray(which stores the flat_id)

But now when I check a row that has a particular flat_id which is common with one of the duplicate user_map_id‘s flat_id and then again check one in that group, the one with the common flat_id does not get disabled because the flat_id I checked above is present in the selectedFlatNumArray(which stores the flat_id).

Explaining in terms of real world

Here’s a screenshot: Image

The rows in the table are a list of flat owners and occupants(both have user_map_id). A flat owner can have multiple flats(hence duplicate user_map_ids in the table). The flat owner can have multiple flats(different flat_ids).

But the flat owner can have an occupant(same flat_id different user_map_id). The occupant can reside in one of the many flats of the flat owner(same flat_id different user_map_id).

I want to be able to check any of the flat owner(others get disabled) and also an occupant(if I want to).

If I check row with one of the flats of the flat owner, the other rows of belonging to same flat owner get disabled and works ok.

But when I check a row with an occupant and then again check a flat owner of that occupant (which does not have same flat_id) the row with same flat_id won’t get disabled because the flat_id is present in the selectedFlatNumArray(which stores the flat_id)

How do I do this?

The table:

 <tbody>
    <tr ng-repeat="flat in someObj.flatsArray | filter:searchFlat">
       <td>{{ flat.occupant_name || flat.owner_name}}</td>
       <td>{{flat.flat_no}}</td>
       <td class="text-center">
     <input class="" name="{{flat.flat_no}}" ng-attr-title="{{(selectedUserMapIdArray.indexOf(flat.user_map_id) >= 0 && selectedFlatNumArray.indexOf(flat.flat_id) < 0) ? 'This user has been already invited' : ''}}"
         ng-disabled="selectedUserMapIdArray.indexOf(flat.user_map_id) >= 0 && selectedFlatNumArray.indexOf(flat.flat_id) < 0 "
     type="checkbox" ng-change="checkChanged(flat.isChecked, flat)" ng-model="flat.isChecked" />
              </td>
</tr>
</tbody>


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.