I have to let the user select items to submit them later on, but my problem occur when selecting multiple items and then search for another items to select them, the previous selected items rested to default values unchecked.
how to keep the checked value to the selected items after calling again getAllItems function? because what happens is that the ng-repeat clear the value of the previous selected items.
My view:
<div id="dialog-items">
// the search box
<input ng-change="getAllItemNames(searchValMultiItems)" ng-model="searchValMultiItems" type="text"/>
<table>
<th>Designation</th>
<th>Colisage</th>
<th>Code</th>
//the mark() function is to set checked value to selected input and store the item in an array
<tr ng-repeat="d in allDesignation" ng-click="markItem(d.itemName); ischeck=true;">
<td ><input type="checkbox" ng-checked="ischeck" /> {{d.itemName}}</td>
<td>{{d.item_colisage}}</td>
<td>{{d.code}}</td>
</tr>
</table>
</div>
JS:
//calling this function to search for an item
$scope.getAllItemNames=function(searchValMultiItems){
var searchItems=searchValMultiItems;
var url="../php/mainPageFacture.php";
var data = {"function":"getAllItemNames","searchValMultiItems":searchItems};
var options={
type : "get",
url : url,
data: data,
dataType: 'json',
async : false,
cache : false,
success : function(response,status) {
$scope.allDesignation=response;
$scope.safeApply(function() {});
},
error:function(request,response,error){
alert("Error");
}
};
$.ajax(options);
}
/*this is responsible to set checked value to true when
item is selected and store all selected item in an array*/
$scope.markItem=function(itemName){
if( $.inArray(itemNameWithCode, multiSelectItem_names) !== -1 ) {
alert("This Item is already added to this Invoice");
}else{
multiSelectItem_names.push(itemNameWithCode);
}
}
I store all selected items in an array and even after search the array keep the value, but problem is only whith the checked mark, i'll attach a photo for more clarification