dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31747
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16220: tracker capture - mandatory and type validation when editing tei profile/attributes
------------------------------------------------------------
revno: 16220
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2014-07-23 14:21:33 +0200
message:
tracker capture - mandatory and type validation when editing tei profile/attributes
modified:
dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js
dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html
dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js 2014-07-15 09:20:54 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile-controller.js 2014-07-23 12:21:33 +0000
@@ -42,6 +42,12 @@
$scope.save = function(){
+ //check for form validity
+ $scope.outerForm.submitted = true;
+ if( $scope.outerForm.$invalid ){
+ return false;
+ }
+
var tei = angular.copy($scope.selectedTei);
tei.attributes = [];
//prepare to update the tei on the server side
@@ -64,6 +70,7 @@
$scope.editProfile = !$scope.editProfile;
CurrentSelection.set({tei: $scope.selectedTei, te: $scope.trackedEntity, pr: $scope.selectedProgram, enrollment: $scope.selectedEnrollment});
+ $scope.outerForm.submitted = false;
});
};
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html 2014-07-23 09:56:14 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/profile/profile.html 2014-07-23 12:21:33 +0000
@@ -13,60 +13,69 @@
</span>
</div>
<div ng-show="profileWidget.expand" class="panel-body dashboard-widget-container">
- <table class="table-borderless table-striped">
- <tr ng-repeat="attribute in selectedTei.attributes" ng-show="attribute.show">
- <td>
- {{attribute.displayName}}
- </td>
- <td>
- <div ng-switch="attribute.type">
- <div ng-switch-when="date">
- <input type="text" class="form-control" ng-date ng-model="attribute.value" value="attribute.value | date:'yyyy-MM-dd" ng-disabled="!editProfile"/>
- </div>
- <div ng-switch-when="trueOnly">
- <input type="checkbox" class="form-control" ng-model="attribute.value" ng-disabled="!editProfile"/>
- </div>
- <div ng-switch-when="bool">
- <select ng-model="attribute.value" class="form-control" ng-disabled="!editProfile">
- <option value="">{{'please_select'| translate}}</option>
- <option value="0">{{'no'| translate}}</option>
- <option value="1">{{'yes'| translate}}</option>
- </select>
- </div>
- <div ng-switch-when="optionSet">
- <input type="text"
- class="form-control"
- ng-model="attribute.value"
- typeahead="option for option in attributes[attribute.attribute].optionSet.options | filter:$viewValue | limitTo:20"
- typeahead-open-on-focus
- ng-disabled="!editProfile"/>
- </div>
- <div ng-switch-when="number">
- <input type="number" class="form-control" ng-model="attribute.value" ng-disabled="!editProfile"/>
- </div>
- <div ng-switch-default>
- <input type="text" class="form-control" ng-model="attribute.value" ng-disabled="!editProfile"/>
- </div>
- </div>
- </td>
- </tr>
- </table>
-
- <div ng-if="editProfile" class="vertical-spacing">
-
- <button type="button"
- class="btn btn-primary small-horizonal-spacing"
- ng-click="save()">
- {{'save'| translate}}
- </button>
- <button type="button"
- class="btn btn-default small-horizonal-spacing"
- ng-click="cancel()">
- {{'cancel'| translate}}
- </button>
-
- </div>
- </div>
-
-
+ <form name="outerForm" novalidate>
+
+ <table class="table-borderless table-striped">
+ <tr ng-repeat="attribute in selectedTei.attributes" ng-show="attribute.show">
+ <td>
+ {{attribute.displayName}} - {{attribute.mandatory}}
+ </td>
+ <td>
+ <ng-form name="innerForm">
+ <div ng-switch="attribute.type">
+ <div ng-switch-when="date">
+ <input type="text" name="foo" class="form-control" ng-date ng-model="attribute.value" value="attribute.value | date:'yyyy-MM-dd" ng-disabled="!editProfile" ng-required="attribute.mandatory"/>
+ <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}} - {{attribute.type}}</span>
+ </div>
+ <div ng-switch-when="trueOnly">
+ <input type="checkbox" name="foo" class="form-control" ng-model="attribute.value" ng-disabled="!editProfile" ng-required="attribute.mandatory"/>
+ <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}} - {{attribute.type}}</span>
+ </div>
+ <div ng-switch-when="bool">
+ <select name="foo" ng-model="attribute.value" class="form-control" ng-disabled="!editProfile" ng-required="attribute.mandatory">
+ <option value="">{{'please_select'| translate}}</option>
+ <option value="0">{{'no'| translate}}</option>
+ <option value="1">{{'yes'| translate}}</option>
+ </select>
+ <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}} - {{attribute.type}}</span>
+ </div>
+ <div ng-switch-when="optionSet">
+ <input type="text"
+ name="foo"
+ class="form-control"
+ ng-model="attribute.value"
+ typeahead="option for option in attributes[attribute.attribute].optionSet.options | filter:$viewValue | limitTo:20"
+ typeahead-open-on-focus
+ ng-disabled="!editProfile" ng-required="attribute.mandatory"/>
+ <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}} - {{attribute.type}}</span>
+ </div>
+ <div ng-switch-when="number">
+ <input type="number" name="foo" class="form-control" ng-model="attribute.value" ng-disabled="!editProfile" ng-required="attribute.mandatory"/>
+ <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}} - {{attribute.type}}</span>
+ </div>
+ <div ng-switch-default>
+ <input type="text" name="foo" class="form-control" ng-model="attribute.value" ng-disabled="!editProfile" ng-required="attribute.mandatory"/>
+ <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="error">{{'required'| translate}} - {{attribute.type}}</span>
+ </div>
+ </div>
+ </ng-form>
+ </td>
+ </tr>
+ </table>
+
+ <div ng-if="editProfile" class="vertical-spacing">
+ <button type="button"
+ class="btn btn-primary small-horizonal-spacing"
+ ng-click="save()">
+ {{'save'| translate}}
+ </button>
+ <button type="button"
+ class="btn btn-default small-horizonal-spacing"
+ ng-click="cancel()">
+ {{'cancel'| translate}}
+ </button>
+ </div>
+
+ </form>
+ </div>
</div>
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-07-21 13:20:58 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js 2014-07-23 12:21:33 +0000
@@ -499,11 +499,12 @@
processed = true;
teiAttributes[j].show = true;
teiAttributes[j].order = i;
+ teiAttributes[j].mandatory = requiredAttributes[i].mandatory ? requiredAttributes[i].mandatory : false;
}
}
if(!processed && fromEnrollment){//attribute was empty, so a chance to put some value
- teiAttributes.push({show: true, order: i, attribute: requiredAttributes[i].id, displayName: requiredAttributes[i].name, type: requiredAttributes[i].valueType, value: ''});
+ teiAttributes.push({show: true, order: i, mandatory: requiredAttributes[i].mandatory ? requiredAttributes[i].mandatory : false, attribute: requiredAttributes[i].id, displayName: requiredAttributes[i].name, type: requiredAttributes[i].valueType, value: ''});
}
}