Skip to content

Commit 1120d57

Browse files
committed
Add validation to addTestBatch
Validation is limited - does not highlight the select box when validation fails, since mg-class cannot be used currently with ui-select - see angular-ui/ui-select#277
1 parent 6177b14 commit 1120d57

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

app/scripts/controllers/testing.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,25 @@ angular.module('bsis')
104104
$scope.getOpenTestBatches();
105105
$scope.getTestBatchFormFields();
106106

107-
$scope.addTestBatch = function (donationBatches){
107+
$scope.addTestBatch = function (donationBatches, valid){
108+
if (valid){
108109

109-
TestingService.addTestBatch(donationBatches, function(response){
110-
if (response === true){
111-
$scope.selectedDonationBatches = {};
112-
$scope.getOpenTestBatches();
113-
$scope.getTestBatchFormFields();
114-
}
115-
else{
116-
// TODO: handle case where response == false
117-
}
118-
});
110+
TestingService.addTestBatch(donationBatches, function(response){
111+
if (response === true){
112+
$scope.selectedDonationBatches = {};
113+
$scope.getOpenTestBatches();
114+
$scope.getTestBatchFormFields();
115+
$scope.submitted = '';
116+
}
117+
else{
118+
// TODO: handle case where response == false
119+
}
120+
});
121+
}
122+
else{
123+
$scope.submitted = true;
124+
console.log("FORM NOT VALID");
125+
}
119126
};
120127

121128
$scope.testBatchTableParams = new ngTableParams({

app/views/testing/manageTestBatch.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ <h4>New Test Batch</h4>
4646
<p><em>There are no current donations to test</em></p>
4747
</div>
4848
<div ng-switch-default>
49-
<form class="form-horizontal col-sm-12" role="form" ng-submit="addTestBatch(selectedDonationBatches.ids)">
49+
<form name="addTestBatchForm" novalidate class="form-horizontal col-sm-12" role="form" ng-submit="addTestBatch(selectedDonationBatches.ids, addTestBatchForm.$valid)">
5050
<div class="form-group">
5151
<label for="name" class="col-sm-2 control-label">Donation Batches</label>
5252
<div class="row col-sm-10">
5353
<div class="form-inline" style="padding-left:5px;">
54-
<ui-select multiple ng-model="selectedDonationBatches.ids" theme="bootstrap" ng-disabled="disabled" style="width: 800px;">
54+
<ui-select name="donationBatches" required multiple ng-model="selectedDonationBatches.ids" theme="bootstrap" ng-disabled="disabled" style="width: 800px;" >
5555
<ui-select-match placeholder="Select:">{{$item.collectionCenter.name}} ({{$item.createdDate}})</ui-select-match>
5656
<ui-select-choices repeat="donationBatch.id as donationBatch in donationBatches | filter:$select.search">
5757
<div ng-bind-html="donationBatch.collectionCenter.name"></div>
@@ -61,14 +61,22 @@ <h4>New Test Batch</h4>
6161
</small>
6262
</ui-select-choices>
6363
</ui-select>
64+
<div>
65+
<small class="error"
66+
ng-show="
67+
(addTestBatchForm.donationBatches.$invalid && (addTestBatchForm.donationBatches.$dirty || submitted))
68+
">
69+
Select one or more donation batches
70+
</small>
71+
</div>
6472
</div>
6573
</div>
6674
</div>
6775

6876
<div class="form-group">
6977
<div class="col-sm-offset-2 col-sm-4">
7078
<button class="btn btn-primary" type="submit">Add Test Batch</button>
71-
<button class="btn btn-primary" type="button" ng-click="clear()">Clear</button>
79+
<button class="btn btn-primary" type="button" ng-click="clearForm(addTestBatchForm); clear()">Clear</button>
7280
</div>
7381
</div>
7482

0 commit comments

Comments
 (0)