← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16780: event capture - empty form validation during registration and free text data entry for string typ...

 

------------------------------------------------------------
revno: 16780
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-09-23 12:48:24 +0200
message:
  event capture - empty form validation during registration and free text data entry for string type dataelements
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/en.json
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/index.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.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-apps/src/main/webapp/dhis-web-event-capture/i18n/en.json'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/en.json	2014-08-21 16:30:01 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/i18n/en.json	2014-09-23 10:48:24 +0000
@@ -33,6 +33,8 @@
     "done": "Done",
     "remove": "Remove",
     "are_you_sure_to_remove": "Are you sure you want to remove the selected item?",
+    "empty_form": "Empty form",
+    "please_fill_at_least_one_dataelement": "Your form is empty. Please fill at least one dataelement.",
     "use_custom_form": "Custom form",
     "use_default_form": "Default form",
     "print_list": "Print list",

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/index.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/index.html	2014-08-22 11:29:33 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/index.html	2014-09-23 10:48:24 +0000
@@ -182,7 +182,7 @@
                             </div>
 
                         </div>
-                    </form>  
+                    </form>
                 </div>
                 <!-- event update / registration ends -->                
             </div>            

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-08-22 11:29:33 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-09-23 10:48:24 +0000
@@ -240,11 +240,11 @@
 
                                 delete $scope.dhis2Events[i].dataValues;
                             }
-                            else{//event is empty, remove from grid
+                            /*else{//event is empty, remove from grid
                                 var index = $scope.dhis2Events.indexOf($scope.dhis2Events[i]);                           
                                 $scope.dhis2Events.splice(index,1);
                                 i--;                           
-                            }
+                            }*/
                         }  
                         
                         if($scope.noteExists){
@@ -406,11 +406,27 @@
         }
         
         //the form is valid, get the values
+        //but there could be a case where all dataelements are non-mandatory and
+        //the event form comes empty, in this case enforce at least one value
+        var valueExists = false;
         var dataValues = [];        
         for(var dataElement in $scope.programStageDataElements){
+            if($scope.currentEvent[dataElement]){
+                valueExists = true;
+            }
             dataValues.push({dataElement: dataElement, value: $scope.currentEvent[dataElement]});
         }
         
+        if(!valueExists){
+            var dialogOptions = {
+                headerText: 'empty_form',
+                bodyText: 'please_fill_at_least_one_dataelement'
+            };
+
+            DialogService.showDialog({}, dialogOptions);
+            return false;
+        }        
+        
         var newEvent = angular.copy($scope.currentEvent);        
         
         //prepare the event to be created

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2014-08-28 12:23:08 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2014-09-23 10:48:24 +0000
@@ -249,13 +249,22 @@
                                             ' ng-required="programStageDataElements.' + deId + '.compulsory">';
                         }
                         if(programStageDataElements[deId].dataElement.type == "string"){
-                            newInputField = '<input type="text" ' +
+                            if(programStageDataElements[deId].dataElement.optionSet){
+                        		newInputField = '<input type="text" ' +
                                             this.getAttributesAsString(attributes) +
                                             ' ng-model="currentEvent.' + deId + '" ' +
                                             ' ng-disabled="currentEvent[uid] == \'uid\'" ' +
                                             ' ng-required="programStageDataElements.' + deId + '.compulsory"' +
                                             ' typeahead="option.code as option.name for option in programStageDataElements.'+deId+'.dataElement.optionSet.options | filter:$viewValue | limitTo:20"' +
                                             ' typeahead-open-on-focus ng-required="programStageDataElements.'+deId+'.compulsory">';
+                        	}
+                        	else{
+                        		newInputField = '<input type="text" ' +
+                                            this.getAttributesAsString(attributes) +
+                                            ' ng-model="currentEvent.' + deId + '" ' +
+                                            ' ng-disabled="currentEvent[uid] == \'uid\'" ' +
+                                            ' ng-required="programStageDataElements.' + deId + '.compulsory">';
+                        	}
                         }
                         if(programStageDataElements[deId].dataElement.type == "bool"){
                             newInputField = '<select ' +

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2014-08-28 12:23:08 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2014-09-23 10:48:24 +0000
@@ -80,9 +80,8 @@
                                        style="width:99%;"/>
                                 <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                             </div>
-                            <div ng-switch-when="string">                                        
-
-                                <div class="container-fluid">                                
+                            <div ng-switch-when="string">                                
+                                <div class="container-fluid" ng-if="programStageDataElements[eventGridColumn.id].dataElement.optionSet">
                                     <span ng-if="!selectedProgram.dataEntryMethod || programStageDataElements[eventGridColumn.id].dataElement.optionSet.options.length > 7">
                                         <input type="text"
                                                ng-model="currentEvent[eventGridColumn.id]"                                                                    
@@ -110,7 +109,15 @@
                                         </label>                                    
                                         <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>                                    
                                     </span>
-                                </div>                            
+                                </div>
+                                <div ng-if="!programStageDataElements[eventGridColumn.id].dataElement.optionSet">
+                                    <input type="text"
+                                        ng-model="currentEvent[eventGridColumn.id]"                                        
+                                        ng-required={{eventGridColumn.compulsory}}
+                                        name="foo" 
+                                        style="width:99%;"/>
+                                    <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
+                                </div>                                
                             </div>
                             <div ng-switch-when="bool">
                                 <select ng-model="currentEvent[eventGridColumn.id]"                                                                
@@ -246,9 +253,8 @@
                                                style="width:99%;"/>
                                         <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
                                     </div>
-                                    <div ng-switch-when="string">                                        
-
-                                        <div class="container-fluid">                                
+                                    <div ng-switch-when="string">
+                                        <div class="container-fluid" ng-if="programStageDataElements[de.dataElement.id].dataElement.optionSet">                                
                                             <span ng-if="!selectedProgram.dataEntryMethod || programStageDataElements[de.dataElement.id].dataElement.optionSet.options.length > 8">
                                                 <input type="text"
                                                        ng-model="currentEvent[de.dataElement.id]"                                                                    
@@ -276,7 +282,15 @@
                                                 </label>                                    
                                                 <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>                                    
                                             </span>
-                                        </div>                            
+                                        </div>
+                                        <div ng-if="!programStageDataElements[de.dataElement.id].dataElement.optionSet">
+                                            <input type="text"
+                                                ng-model="currentEvent[de.dataElement.id]"
+                                                ng-required={{programStageDataElements[de.dataElement.id].compulsory}}
+                                                name="foo" 
+                                                style="width:99%;"/>
+                                            <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>
+                                        </div>
                                     </div>
                                     <div ng-switch-when="bool">
                                         <select ng-model="currentEvent[de.dataElement.id]"                                                                

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html	2014-08-28 12:23:08 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/eventList.html	2014-09-23 10:48:24 +0000
@@ -135,53 +135,66 @@
                                             <span ng-show="outerForm.submitted && innerFormGrid.foo.$invalid" class="red"><em title="{{'required'| translate}}" class="required">*</em></span>
                                         </div>
                                         <div ng-switch-when="string">                                        
-                            
-                                            <div class="container-fluid">
-                                                <span ng-if="eventGridColumn.id == 'uid'">
-                                                    <input type="text"
-                                                           ng-model="currentEvent[eventGridColumn.id]"                                                                    
-                                                           ng-disabled=true
+                                            <div ng-if="eventGridColumn.id == 'uid'">
+                                                <input type="text"
+                                                       ng-model="currentEvent[eventGridColumn.id]"                                                                    
+                                                       ng-disabled=true
+                                                       name="foo" 
+                                                       style="width:99%;"/>                                                    
+                                            </div>
+                                            <div ng-if="eventGridColumn.id !== 'uid'">
+                                                <div class="container-fluid" ng-if="programStageDataElements[eventGridColumn.id].dataElement.optionSet">                                                
+                                                    <span ng-if="!selectedProgram.dataEntryMethod || programStageDataElements[eventGridColumn.id].dataElement.optionSet.options.length > 7">
+                                                        <input type="text" 
+                                                           ng-model="dhis2Event[eventGridColumn.id]" 
+                                                           ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
+                                                           typeahead="option.code as option.name for option in programStageDataElements[eventGridColumn.id].dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
+                                                           typeahead-open-on-focus
+                                                           ng-required={{eventGridColumn.compulsory}}
+                                                           ng-disabled="eventGridColumn.id == 'uid'"
                                                            name="foo" 
-                                                           style="width:99%;"/>                                                    
-                                                </span>
-                                                <span ng-if="eventGridColumn.id !== 'uid' && !selectedProgram.dataEntryMethod || programStageDataElements[eventGridColumn.id].dataElement.optionSet.options.length > 7">
+                                                           style="width:98%;"
+                                                           ng-class="{true: 'update-success'} [currentElement.updated == true && currentElement.id == eventGridColumn.id]"
+                                                           ng-class="{true: 'update-error'} [!currentElement.updated == true && currentElement.id == eventGridColumn.id]"
+                                                           />
+                                                        <span ng-show="outerForm.submitted && innerFormGrid.foo.$invalid" class="red"><em title="{{'required'| translate}}" class="required">*</em></span>
+                                                    </span>
+                                                    <span ng-if="selectedProgram.dataEntryMethod && programStageDataElements[eventGridColumn.id].dataElement.optionSet.options.length < 7">                                    
+                                                        <label>
+                                                            <input type="radio" 
+                                                                   name="foo" 
+                                                                   ng-required={{eventGridColumn.compulsory}}
+                                                                   ng-model="dhis2Event[eventGridColumn.id]" 
+                                                                   ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
+                                                                   value=""> {{'no_value' | translate}}<br>                                     
+                                                        </label>                                    
+                                                        <label ng-repeat="option in  programStageDataElements[eventGridColumn.id].dataElement.optionSet.options">
+                                                            <input type="radio" 
+                                                                   name={{eventGridColumn.id}}   
+                                                                   ng-required={{eventGridColumn.compulsory}}
+                                                                   ng-model="dhis2Event[eventGridColumn.id]" 
+                                                                   ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)"
+                                                                   ng-class="{true: 'update-success'} [currentElement.updated == true && currentElement.id == eventGridColumn.id]"
+                                                                   ng-class="{true: 'update-error'} [!currentElement.updated == true && currentElement.id == eventGridColumn.id]"
+                                                                   value={{option.code}}> {{option.name}}<br>                                    
+                                                        </label>                                    
+                                                        <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>                                    
+                                                    </span>                                                
+                                                </div>
+                                                <div ng-if="!programStageDataElements[eventGridColumn.id].dataElement.optionSet">
                                                     <input type="text" 
-                                                       ng-model="dhis2Event[eventGridColumn.id]" 
-                                                       ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
-                                                       typeahead="option.code as option.name for option in programStageDataElements[eventGridColumn.id].dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
-                                                       typeahead-open-on-focus
-                                                       ng-required={{eventGridColumn.compulsory}}
-                                                       ng-disabled="eventGridColumn.id == 'uid'"
-                                                       name="foo" 
-                                                       style="width:98%;"
-                                                       ng-class="{true: 'update-success'} [currentElement.updated == true && currentElement.id == eventGridColumn.id]"
-                                                       ng-class="{true: 'update-error'} [!currentElement.updated == true && currentElement.id == eventGridColumn.id]"
-                                                       />
+                                                        ng-model="dhis2Event[eventGridColumn.id]" 
+                                                        ng-blur="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
+                                                        ng-required={{eventGridColumn.compulsory}}
+                                                        ng-disabled="eventGridColumn.id == 'uid'"
+                                                        name="foo" 
+                                                        style="width:98%;"
+                                                        ng-class="{true: 'update-success'} [currentElement.updated == true && currentElement.id == eventGridColumn.id]"
+                                                        ng-class="{true: 'update-error'} [!currentElement.updated == true && currentElement.id == eventGridColumn.id]"
+                                                        />
                                                     <span ng-show="outerForm.submitted && innerFormGrid.foo.$invalid" class="red"><em title="{{'required'| translate}}" class="required">*</em></span>
-                                                </span>
-                                                <span ng-if="eventGridColumn.id !== 'uid' && selectedProgram.dataEntryMethod && programStageDataElements[eventGridColumn.id].dataElement.optionSet.options.length < 7">                                    
-                                                    <label>
-                                                        <input type="radio" 
-                                                               name="foo" 
-                                                               ng-required={{eventGridColumn.compulsory}}
-                                                               ng-model="dhis2Event[eventGridColumn.id]" 
-                                                               ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
-                                                               value=""> {{'no_value' | translate}}<br>                                     
-                                                    </label>                                    
-                                                    <label ng-repeat="option in  programStageDataElements[eventGridColumn.id].dataElement.optionSet.options">
-                                                        <input type="radio" 
-                                                               name={{eventGridColumn.id}}   
-                                                               ng-required={{eventGridColumn.compulsory}}
-                                                               ng-model="dhis2Event[eventGridColumn.id]" 
-                                                               ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)"
-                                                               ng-class="{true: 'update-success'} [currentElement.updated == true && currentElement.id == eventGridColumn.id]"
-                                                               ng-class="{true: 'update-error'} [!currentElement.updated == true && currentElement.id == eventGridColumn.id]"
-                                                               value={{option.code}}> {{option.name}}<br>                                    
-                                                    </label>                                    
-                                                    <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'required'| translate}}</span>                                    
-                                                </span>
-                                                
-                                            </div>                            
+                                                </div>
+                                            </div>
                                         </div>                                        
                                         <div ng-switch-when="bool">
                                             <select ng-model="dhis2Event[eventGridColumn.id]"