Skip to content

Commit

Permalink
fix: [DHIS2-14190] assign null instead of non-existing option (#1677)
Browse files Browse the repository at this point in the history
  • Loading branch information
superskip authored Mar 22, 2023
1 parent 39ad51a commit 37a6cdd
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions d2-tracker/dhis2.angular.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,22 +447,48 @@ var d2Services = angular.module('d2Services', ['ngResource'])
return {
getCode: function(options, key){
if(options){
// for comparison with the option values, which are always represented as strings
const keyString = String(key);

// is key a name?
for(var i=0; i<options.length; i++){
if( key === options[i].displayName){
if( keyString === options[i].displayName){
return options[i].code;
}
}
// is key a code?
for(var i=0; i<options.length; i++){
if( keyString === options[i].code){
return key;
}
}
// not a part of the option set
return null;
}

return key;
},
getName: function(options, key){
if(options){
// for comparison with the option values, which are always represented as strings
const keyString = String(key);

// is key a code?
for(var i=0; i<options.length; i++){
if( key === options[i].code){
if( keyString === options[i].code){
return options[i].displayName;
}
}
// is key a name?
for(var i=0; i<options.length; i++){
if( keyString === options[i].displayName){
return key;
}
}
// not a part of the option set
return null;
}

return key;
}
};
Expand Down

0 comments on commit 37a6cdd

Please sign in to comment.