Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix : Gender question - 'I don't know' for additional people shows up as 'add-gender-unknown' #158

Closed
wants to merge 12 commits into from
12 changes: 8 additions & 4 deletions apps/paf/behaviours/additional-person-formatter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const _ = require('lodash');
const fieldsMap = require('../../../lib/ims-hof-fields-map.json');
const valuesMap = require('../../../lib/ims-hof-person-add-values.json');

const transform = item => {
const value = _.find(valuesMap.Values, {HOF: item.value});
const imsValue = value === undefined ? item.value : value.IMS;
return {Key: _.find(fieldsMap.Fields, {HOF: item.field}).IMS, StringValue: imsValue};
};

module.exports = superclass => class extends superclass {
configure(req, res, next) {
Expand All @@ -10,11 +17,8 @@ module.exports = superclass => class extends superclass {
_.forEach(persons.aggregatedValues, i => {
const person = new Array();
i.fields.map(item => item.value !== '' ?
person.push({Key: _.find(fieldsMap.Fields, {HOF: item.field}).IMS,
StringValue: item.value}) : '');

person.push(transform(item)) : '');
additionalPeople.push(person);

req.sessionModel.set('persons', additionalPeople);
});
} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/paf/behaviours/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ module.exports = superclass => class extends superclass {
parseField(field, value, req) {
const fieldName = field.field || field;
const parser = req.form.options.fieldsConfig[fieldName].parse;
return parser ? parser(value) : value;
return parser ? parser(value, fieldName, req) : value;
}

locals(req, res) {
Expand Down
7 changes: 4 additions & 3 deletions apps/paf/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,10 +1240,11 @@ module.exports = {
personAddGender: {
mixin: 'radio-group',
isPageHeading: true,
parse: (value, field, req) => req.translate(`fields[${field}].options.[${value}]`),
options: [
'Male',
'Female',
'Other',
'male',
'female',
'other',
'add-gender-unknown'
]
},
Expand Down
6 changes: 3 additions & 3 deletions apps/paf/translations/src/en/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -1187,13 +1187,13 @@
"personAddGender": {
"legend": "What is the person's gender?",
"options": {
"Male": {
"male": {
"label": "Male"
},
"Female": {
"female": {
"label": "Female"
},
"Other": {
"other": {
"label": "Other"
},
"add-gender-unknown": {
Expand Down
8 changes: 8 additions & 0 deletions lib/ims-hof-person-add-values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Values": [
{ "HOF": "male", "IMS": "Male" },
{ "HOF": "female", "IMS": "Female" },
{ "HOF": "other", "IMS": "Other" },
{ "HOF": "add-gender-unknown", "IMS": "IDontKnow"}
]
}
3 changes: 1 addition & 2 deletions lib/ims-hof-values-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@
{ "HOF": "study-manager-know-unknown", "IMS": "DontKnow" },
{ "HOF": "transport-unknown", "IMS": "Idontknow" },
{ "HOF": "report-org-unknown", "IMS": "Idontknow" },
{ "HOF": "org-owner-know-unknown", "IMS": "dontknow" },
{ "HOF": "add-gender-unknown", "IMS": "IDontKnow"}
{ "HOF": "org-owner-know-unknown", "IMS": "dontknow" }
]
}