← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17533: optionset input fields - allow typing but clear invalid option after blur; show caret icon to not...

 

------------------------------------------------------------
revno: 17533
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-11-19 13:00:31 +0100
message:
  optionset input fields - allow typing but clear invalid option after blur; show caret icon to notify selection is possible
modified:
  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/directives.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/styles/style.css
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.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/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-11-19 09:29:44 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-11-19 12:00:31 +0000
@@ -121,7 +121,10 @@
 
         $scope.eventFetched = false;
                
-        if( $scope.selectedProgram && $scope.selectedProgram.programStages[0].id){
+        if( $scope.selectedProgram && 
+                $scope.selectedProgram.programStages && 
+                $scope.selectedProgram.programStages[0] && 
+                $scope.selectedProgram.programStages[0].id){
             
             $scope.optionSets = [];
             OptionSetService.getAll().then(function(optionSets){
@@ -231,7 +234,10 @@
                                                     }                                        
                                                 }
                                                 if($scope.prStDes[dataValue.dataElement].dataElement.type === 'string'){
-                                                    if($scope.prStDes[dataValue.dataElement].dataElement.optionSet ){
+                                                    if($scope.prStDes[dataValue.dataElement].dataElement.optionSet &&
+                                                            $scope.prStDes[dataValue.dataElement].dataElement.optionSet.id &&
+                                                            $scope.optionSets[$scope.prStDes[dataValue.dataElement].dataElement.optionSet.id] &&
+                                                            $scope.optionSets[$scope.prStDes[dataValue.dataElement].dataElement.optionSet.id].options ){
                                                         val = OptionSetService.getNameOrCode($scope.optionSets[$scope.prStDes[dataValue.dataElement].dataElement.optionSet.id].options, val);
                                                     }                                                
                                                 }

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js	2014-11-12 16:49:17 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/directives.js	2014-11-19 12:00:31 +0000
@@ -248,10 +248,26 @@
     };
 })
 
+.directive('d2TypeaheadValidation', function() {
+    
+    return {
+        require: 'ngModel',
+        restrict: 'A',
+        link: function (scope, element, attrs, ctrl) {
+            element.bind('blur', function () {                
+                if(ctrl.$viewValue && !ctrl.$modelValue){
+                    ctrl.$setViewValue();
+                    ctrl.$render();
+                }                
+            });
+        }
+    };
+})
+
 .directive('typeaheadOpenOnFocus', function () {
   return {
         require: ['typeahead', 'ngModel'],
-        link: function (scope, element, attr, ctrls) {        
+        link: function (scope, element, attr, ctrls) {
             element.bind('focus', function () {
                 ctrls[0].getMatchesAsync(ctrls[1].$viewValue);
                 

=== 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-11-19 09:55:11 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/scripts/services.js	2014-11-19 12:00:31 +0000
@@ -391,6 +391,7 @@
                                             ' ng-required="prStDes.' + deId + '.compulsory"' +
                                             ' typeahead="option.name as option.name for option in optionSets.'+optionSetId+'.options | filter:$viewValue | limitTo:20"' +
                                             ' typeahead-editable="false" ' +
+                                            ' d2-typeahead-validation ' +
                                             ' typeahead-open-on-focus ng-required="prStDes.'+deId+'.compulsory"> ' +
                                             '<span ng-show="outerForm.submitted && outerForm.'+ deId +'.$invalid" class="required">{{\'option_required\'| translate}}</span>';
                         	}
@@ -400,7 +401,7 @@
                                             ' ng-model="currentEvent.' + deId + '" ' +
                                             ' ng-disabled="currentEvent[uid] == \'uid\'" ' +
                                             ' ng-required="prStDes.' + deId + '.compulsory"> ' +
-                                            '<span ng-show="outerForm.submitted && outerForm.'+ deId +'.$invalid" class="required">{{\'text_required\'| translate}}</span>';                                     
+                                            '<span ng-show="outerForm.submitted && outerForm.'+ deId +'.$invalid" class="required">{{\'string_required\'| translate}}</span>';                                     
                         	}
                         }
                         if(programStageDataElements[deId].dataElement.type == "bool"){

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css	2014-11-19 09:29:44 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/styles/style.css	2014-11-19 12:00:31 +0000
@@ -866,6 +866,25 @@
     margin-right: 20px;    
 }
 
+input.typeahead::-webkit-input-placeholder {
+    font-family: fontAwesome;
+    content: "\f0d7";
+    text-align: right;
+    font-weight: bold;
+}
+input.typeahead::-moz-placeholder {
+    font-family: fontAwesome;
+    content: "\f0d7";
+    text-align: right;
+    font-weight: bold;
+}
+input.typeahead::-ms-input-placeholder {
+    font-family: fontAwesome;
+    content: "\f0d7";
+    text-align: right;
+    font-weight: bold;
+}
+
 
 @media print {
     #header, #leftBar, .not-printable {

=== 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-11-19 09:55:11 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-capture/views/defaultForm.html	2014-11-19 12:00:31 +0000
@@ -86,10 +86,13 @@
                                 <div class="container-fluid" ng-if="prStDes[eventGridColumn.id].dataElement.optionSet">
                                     <span ng-if="!selectedProgram.dataEntryMethod || optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options.length >= 7">
                                         <input type="text"
+                                               class="typeahead"
+                                               placeholder="&#xf0d7;&nbsp;&nbsp;"
                                                ng-model="currentEvent[eventGridColumn.id]"                                                                    
                                                typeahead="option.name as option.name for option in optionSets[prStDes[eventGridColumn.id].dataElement.optionSet.id].options | filter:$viewValue | limitTo:20" 
                                                typeahead-open-on-focus   
                                                typeahead-editable=false
+                                               d2-typeahead-validation
                                                ng-required={{eventGridColumn.compulsory}}
                                                name="foo" 
                                                style="width:99%;"/>
@@ -119,7 +122,7 @@
                                         ng-required={{eventGridColumn.compulsory}}
                                         name="foo" 
                                         style="width:99%;"/>
-                                    <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'text_required'| translate}}</span>
+                                    <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'string_required'| translate}}</span>
                                 </div>                                
                             </div>
                             <div ng-switch-when="bool">
@@ -264,6 +267,7 @@
                                                        typeahead="option.name as option.name for option in prStDes[de.dataElement.id].dataElement.optionSet.options | filter:$viewValue | limitTo:20" 
                                                        typeahead-open-on-focus   
                                                        typeahead-editable="false"
+                                                       d2-typeahead-validation
                                                        ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                        name="foo" 
                                                        style="width:99%;"/>
@@ -293,7 +297,7 @@
                                                 ng-required={{prStDes[de.dataElement.id].compulsory}}
                                                 name="foo" 
                                                 style="width:99%;"/>
-                                            <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'text_required'| translate}}</span>
+                                            <span ng-show="outerForm.submitted && innerForm.foo.$invalid" class="required">{{'string_required'| translate}}</span>
                                         </div>
                                     </div>
                                     <div ng-switch-when="bool">