I am trying to create a validation in my app.
What I have, is multiple lists with a toggle (true/false).
If the item is selected, it populates an array.
And I have a different array for each group.
Pretty much something like this:
$scope.selected = {
group1: {
values: []
},
group2: {
values: []
},
group3: {
values: []
}
}
When I select something, let's say, from the list in group 1, $scope.selected changes to this:
$scope.selected = {
group1: {
values: [{cat: 1, id: 1},{cat:1, id:3}]
}
}
The problem I've got is that I am trying to validate this.
What I need is to be able to display a message if multiple values arrays are greater than 0.
For instance if:
$scope.selected = {
group1: {
values: [{cat: 1, id: 1},{cat:1, id:3}]
},
group2: {
values: [{cat: 2, id: 5},{cat:2, id:2}]
}
}
a message should appear as I can't allow to submit multiple groups at once.
I know that I can have some sort of function that checks on the specific name for the groups, but I need something a bit more dynamic, as groups may (and will) increase at some point (ie. I will have more groups that the ones I have now).
Is there any way I can check that only one out of all my group arrays is not empty, and if multiple are not empty, I show something?
thanks and I hope it's clear enough