← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15767: form validation during registration

 

------------------------------------------------------------
revno: 15767
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Thu 2014-06-19 14:56:21 +0200
message:
  form validation during registration
modified:
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js
  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/views/search.html


--
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/registration/registration-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2014-06-06 13:35:06 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2014-06-19 12:56:21 +0000
@@ -37,14 +37,18 @@
     
     $scope.registerEntity = function(showDashboard){
         
+        //check for form validity
+        $scope.outerForm.submitted = true;        
+        if( $scope.outerForm.$invalid ){
+            return false;
+        }
+        
+        //form is valid, continue the registration
         //get selected entity
-        var selectedTrackedEntity = '';        
+        var selectedTrackedEntity = $scope.trackedEntities.selected.id; 
         if($scope.selectedProgram){
             selectedTrackedEntity = $scope.selectedProgram.trackedEntity.id;
         }
-        else{
-            selectedTrackedEntity = $scope.trackedEntities.selected.id;
-        }
         
         //get tei attributes and their values
         var registrationAttributes = [];    
@@ -97,18 +101,18 @@
                 return;
             }
             
+            //reset form
+            angular.forEach($scope.attributes, function(attribute){
+                attribute.value = ''; 
+            });
+            $scope.enrollment.enrollmentDate = '';
+            $scope.enrollment.incidentDate =  '';
+            $scope.outerForm.submitted = false; 
+            
             if(showDashboard){
                 $location.path('/dashboard').search({selectedEntityId: teiId,
                                                 selectedProgramId: $scope.selectedProgram ? $scope.selectedProgram.id : null});
-            }
-            else{            
-                
-                angular.forEach($scope.attributes, function(attribute){
-                    attribute.value = ''; 
-                });
-                $scope.enrollment.enrollmentDate = '';
-                $scope.enrollment.incidentDate =  '';
-            }
+            }            
         });
     };
 });
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html	2014-05-27 14:50:29 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html	2014-06-19 12:56:21 +0000
@@ -25,35 +25,45 @@
                         {{attribute.name}}
                     </td>
                     <td>
-                        <div ng-switch="attribute.valueType">
-                            <div ng-switch-when="date">
-                                <input type="text" class="form-control" ng-date ng-model="attribute.value" />
-                            </div>
-                            <div ng-switch-when="trueOnly">
-                                <input type="checkbox" class="form-control" ng-model="attribute.value" />
-                            </div>
-                            <div ng-switch-when="bool">
-                                <select ng-model="attribute.value" class="form-control">
-                                    <option value="">{{'please_select'| translate}}</option>                        
-                                    <option value="0">{{'no'| translate}}</option>
-                                    <option value="1">{{'yes'| translate}}</option>
-                                </select>
-                            </div>
-                            <div ng-switch-when="combo">
-                                <input type="text" 
-                                       class="form-control"
-                                       ng-model="attribute.value"                                                 
-                                       typeahead="option for option in attribute.optionSet.options | filter:$viewValue | limitTo:20" 
-                                       typeahead-open-on-focus 
-                                       />
-                            </div>
-                            <div ng-switch-when="number">
-                                <input type="number" class="form-control" ng-model="attribute.value"/>
-                            </div>
-                            <div ng-switch-default>
-                                <input type="text" class="form-control" ng-model="attribute.value" />                                        
-                            </div>
-                        </div>                                                                                                    
+                        <ng-form name="innerForm">     
+                            <div ng-switch="attribute.valueType">
+                                <div ng-switch-when="date">
+                                    <input type="text" name="foo" class="form-control" ng-date ng-model="attribute.value" ng-required="attribute.mandatory" />
+                                    <span ng-show="outerForm.submitted && innerForm.foo.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                                </div>
+                                <div ng-switch-when="trueOnly">
+                                    <input type="checkbox" name="foo" class="form-control" ng-model="attribute.value" ng-required="attribute.mandatory" />
+                                    <span ng-show="outerForm.submitted && innerForm.foo.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                                </div>
+                                <div ng-switch-when="bool">
+                                    <select name="foo" ng-model="attribute.value" class="form-control" 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" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                                </div>
+                                <div ng-switch-when="optionSet">
+                                    <input type="text"
+                                           name="foo"
+                                           class="form-control"
+                                           ng-model="attribute.value"                                                 
+                                           typeahead="option for option in attribute.optionSet.options | filter:$viewValue | limitTo:20" 
+                                           typeahead-open-on-focus
+                                           ng-required="attribute.mandatory"
+                                           />
+                                    <span ng-show="outerForm.submitted && innerForm.foo.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                                </div>
+                                <div ng-switch-when="number">
+                                    <input type="number" name="foo" class="form-control" ng-model="attribute.value" ng-required="attribute.mandatory"/>
+                                    <span ng-show="outerForm.submitted && innerForm.foo.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                                </div>
+                                <div ng-switch-default>
+                                    <input type="text" name="foo" class="form-control" ng-model="attribute.value" ng-required="attribute.mandatory"/>
+                                    <span ng-show="outerForm.submitted && innerForm.foo.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
+                                </div>
+                            </div>
+                        </ng-form>
                     </td>
                 </tr>                        
             </table>
@@ -67,7 +77,8 @@
                             {{selectedProgram.dateOfEnrollmentDescription}}
                         </td>
                         <td>
-                            <input type="text" class="form-control" ng-date ng-model="enrollment.incidentDate" />
+                            <input type="text" name="dateOfEnrollment" class="form-control" ng-date ng-model="enrollment.incidentDate" ng-required="true"/>
+                            <span ng-show="outerForm.submitted && outerForm.dateOfEnrollment.$invalid" style="color:red;font-size:12px">{{'required'| translate}}</span>
                         </td>
                     </tr>     
                     <tr ng-if="selectedProgram.displayIncidentDate">

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-06-19 09:41:56 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-06-19 12:56:21 +0000
@@ -38,7 +38,7 @@
     $scope.showSearchDiv = false;
     $scope.searchText = null;
     $scope.emptySearchText = false;
-    $scope.searchFilterExists = false;    
+    $scope.searchFilterExists = false;   
     
     $scope.searchMode = { 
                             listAll: 'LIST_ALL', 
@@ -65,8 +65,13 @@
             $scope.loadPrograms($scope.selectedOrgUnit); 
             
             AttributesFactory.getWithoutProgram().then(function(atts){
-                $scope.attributes = atts;
-                $scope.search($scope.searchMode.listAll);
+                setTimeout(function () {
+                    $scope.$apply(function () {
+                        $scope.attributes = atts;   
+                        $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
+                        $scope.search($scope.searchMode.listAll);
+                    });
+                }, 100);
             });           
         }
     });
@@ -90,10 +95,13 @@
                 
                 if(angular.isObject($scope.programs) && $scope.programs.length === 1){
                     $scope.selectedProgram = $scope.programs[0];
-                    
                     AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
-                        $scope.attributes = atts;
-                        $scope.generateGridColumns($scope.attributes);
+                        setTimeout(function () {
+                            $scope.$apply(function () {
+                                $scope.attributes = atts;    
+                                $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
+                            });
+                        }, 100);
                     });
                 }                
             });
@@ -106,16 +114,24 @@
        
         if($scope.selectedProgram){
             AttributesFactory.getByProgram($scope.selectedProgram).then(function(atts){
-                $scope.attributes = atts;
-                $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
+                setTimeout(function () {
+                    $scope.$apply(function () {
+                        $scope.attributes = atts; 
+                        $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
+                    });
+                }, 100);
             });           
         }
         else{
             AttributesFactory.getWithoutProgram().then(function(atts){
-                $scope.attributes = atts;
-                $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
+                setTimeout(function () {
+                    $scope.$apply(function () {
+                        $scope.attributes = atts;    
+                        $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
+                    });
+                }, 100);
             });
-        }
+        }        
         
         if(doSearch){
             $scope.search($scope.searchMode);
@@ -209,14 +225,6 @@
         $scope.showSearchDiv = false;
     };  
     
-    $scope.showSearch = function(){        
-        $scope.showSearchDiv = !$scope.showSearchDiv;
-        $scope.showRegistrationDiv = false;
-        //$scope.showTrackedEntityDiv = false;   
-        $scope.selectedProgram = '';
-        $scope.emptySearchAttribute = false;
-    };
-    
     $scope.hideSearch = function(){        
         $scope.showSearchDiv = false;
         $rootScope.showAdvancedSearchDiv = false;

=== 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-06-19 10:07:22 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-06-19 12:56:21 +0000
@@ -337,9 +337,13 @@
                 });
 
                 angular.forEach(program.programTrackedEntityAttributes, function(pAttribute){
-                    programAttributes.push(attributes[pAttribute.trackedEntityAttribute.id]);                
+                    var att = attributes[pAttribute.trackedEntityAttribute.id];
+                    att.mandatory = pAttribute.mandatory;
+                    if(pAttribute.displayInList){
+                        att.displayInListNoProgram = true;
+                    }                    
+                    programAttributes.push(att);                
                 });
-                
                 def.resolve(programAttributes);                                  
             });
             return def.promise;    

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/search.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/search.html	2014-06-19 09:37:45 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/search.html	2014-06-19 12:56:21 +0000
@@ -14,17 +14,6 @@
                 <input type="text" class="form-control-select2" ng-date ng-model="attribute.value" />
             </td>
         </tr>
-        <tr>
-            <td>{{'program'| translate}}</td>
-            <td>
-                <select class="form-control-select2"
-                        ng-model="selectedProgram" 
-                        ng-change="getProgramAttributes(selectedProgram, false)"
-                        ng-options="program as program.name for program in programs | orderBy: 'name'">
-                    <option value="">{{'please_select'| translate}}</option>
-                </select>
-            </td>
-        </tr>
         <tr ng-repeat="attribute in attributes">
             <td>
                 {{attribute.name}} - {{attribute.valueType}}
@@ -75,8 +64,4 @@
         {{'cancel'| translate}}
     </button>
 
-</div>
-
-
-
-
+</div>
\ No newline at end of file