That's my problem: I could have this array of objects:
[{
"name": "Alex",
"code": "05422180283",
"pIva": "05422180283",
"subCode": null
}, {
"name": "John",
"code": null,
"pIva": null,
"subCode": "IT"
}, {
"name": "Billy",
"code": null,
"pIva": null,
"subCode": "IT"
}, {
"name": "Tom",
"code": null,
"pIva": null,
"subCode": "IT"
}]
This json is used in a form by an ng-repeat and the null field should be filled. When the submit button is pressed the system should be check if there are still empty field. So the situation could be this one now:
[{
"name": "Alex",
"code": "05422180283",
"pIva": "05422180283",
"subCode": null
}, {
"name": "John",
"code": "88985556",
"pIva": "1919ASVVV",
"subCode": "9991VVVV"
}, {
"name": "Billy",
"code": "89952366555",
"pIva": "BB588918989",
"subCode": "ASA234434"
}, {
"name": "Tom",
"code": null,
"pIva": "541198198",
"subCode": "ACEVV9999"
}]
As you can see there are 2 null fields. In this situation the system should be advise the user that there are 2 empty fields. (with an alert or something like that). Otherwise the user can submit the form without any problem. This is what i've done so far:
angular.forEach($scope.myArray, function(items){
if(_.chain(items).find(_.isNull).isNull().value()) {
//console.log('Found one');
formHasEmptyFields = true;
} else {
//console.log('Did not find one');
formHasEmptyFields = false;
}
if(_(items).find(_.isNull) === null) {
//console.log('Found one');
formHasEmptyFields = true;
} else {
//console.log('Did not find one');
formHasEmptyFields = false;
}
});
if(formHasEmptyFields == true) {
alert('There are empty fields');
} else {
submitFunction($scope.myArray);
}
But it doesn't work because seems that it check only the last object. In fact, if I fill the last object in the form it doesn't show me the alert. Any idea? $scope.myArray is my array of objects of course