All checkboxes in the list is getting checked for maybe wrong value passing in ng-model

Prity Shaw
Tera Contributor

I have a requirement to create a custom widget for showing all case records and each case will be attached to a checkbox. So, whenever the checkbox is checked, the case item need to be pushed to an array.
Now, as for populating the case records I used ng-repeat, so even if i am checking on checkbox it is automatically checking all the items in the list. For the below portal snapshot, i just clicked on 1 case and system checked rest 2 automatically. which should not happen.

Assumption :This might be causing for the data passed in ng-model=c.data.item.. But i am not clear what value shall i pass in ng-model, so in client script i will get the item information as well as the checked/unchecked information and if it check 1 item in the list it should not check others.

6 REPLIES 6

Hi Prity,

Keep ng-model

In client script you have configured many alerts, which one is not showing ?

 

I feel there is error in the below line

if (c.data.item == true)

replace this with 

if (c.data.item != "") 

As c.data.item is an array it will not contain value true or false

Also while popping alert spelling is misspelt

 

Prity Shaw
Tera Contributor

HTML Part
<table ng-if="data.items.length" class="grid-table" class="tableContent">
<thead>
<tr>
<td><input type="checkbox" id="selectAll" value="selectAll"></td>
<th ng-repeat="field in ::data.row">{{field}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in data.cases.list">
<td><input type="checkbox" id="{{::item.number}}" value="{{::item.number}}" name="{{::item.number}}" ng-model="c.data.item" ng-change="c.toggle({{item}})"></td>
<td role="cell" ng-repeat="field in ::data.row">{{item[field]}}</td>
</tr>
</tbody>
</table>