<tr ng-repeat="labour in labourdata">
<td>{{$index+1}}</td>
<td data-title="'Mobile No'" sortable="Mobile no">
<input type="text" class="form-control" name="mobile" id="mobile" ng-model="labour.mobile" value={{labour.mobile}} placeholder="Enter Aadhaar" typeahead="mobile.Mobileid for mobile in MobileArray" ng-blur="change_mobile(mobile)" >
</td>
<td data-title="'NAME'" sortable="NAME">
<input type="hidden" ng-model="labour.lid" id="lid" name="lid" />
<input type="text" class="form-control" id="name" ng-model="labour.name" placeholder="Name" readonly>
</td>
<td>
<input type="button" ng-click="addFormField(mobile)" class="btn btn-default" value="Add " />
</td>
</tr>
Here is Js code
//Get Mobile Number
$scope.labourdata = [{}];
$scope.MobileArray = [];
$http({method: 'GET',url: 'get-num.php',labourdata: { applicationId: 3 }})
.success(function (labourdata)
{
$scope.MobileArray = labourdata;
});
// Change Mobile number
$scope.change_mobile=function(mobile)
{
var j=-1;
var mobile = "";
for (var i = 0; i < $scope.labourdata.length; i++)
{
j++;
mobile = $scope.labourdata[i]["mobile"];
}
$http.post('get-labour-details.php', {'selectedmobile': mobile})
.success(function (data, status, headers, config)
{
var comArr = eval($scope.labourdata);
comArr[j].lid = data[0]["LabourId"];
comArr[j].name = data[0]["Name"];
});
}
//Add one more Field
$scope.labourdata = [{}];
$scope.addFormField = function(mobile)
{
var mobile = "";
var found = $scope.labourdata.reduce(function(previous, i)
{
if (mobile === i) return true;
return previous;
}, false);
if (found){
alert('already taken.');
}
else
{
alert('ok');
$scope.labourdata.push({});
}
}
Unable to validate input field in ng-repeat.
if we given Mobile No input filed as a '9999999999'. it displaying 'XXX' name in NAME input field.
When i click on Add button, the next row appears. Problem is while adding one more time Mobile No input filed as a '9999999999'. it should be alert as a it's already taken. because i already selected Mobile no '9999999999' previously.
How to validate input data in iteration while clicking Add button. Is there is any way to solve this problem?