Need help with selecting common items using Angular checkboxes.
Below is the mock UI-Table:
Order Id | Delivery Mode | Select
1 | Speed | ::checkbox::
2 | Normal | ::checkbox::
3 | Contractor | ::checkbox::
4 | Contractor | ::checkbox::
5 | Normal | ::checkbox::
6 | Speed | ::checkbox::
7 | Speed | ::checkbox::
:::Create Order button:::
Conditions:
- All checkboxes are enabled by default and can only select orders of the same delivery mode.
- If mixed delivery modes are selected, display an error message (like an alert).
Orders list used for populating the table:
var orders = [
{
orderId: 1,
deliveryMode: 'Speed'
},
{
orderId: 2,
deliveryMode: 'Normal'
},
...
...
];
Controller logic:
$scope.createOrder = function(order) {
if(order.selected){
$scope.collectOrders.push(order.deliveryMode);
}else{
_.remove($scope.collectOrders, function(order){
return order === order.deliveryMode;
});
}
if (_.uniq($scope.collectOrders).length > 1){
alert('Mixed Delivery mode selected');
}
};
Looking for a more efficient solution to only allow selection of common delivery mode. Any suggestions?