Skip to content

Commit

Permalink
fix: textKeys for select/multiselet questions in loops
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Dec 17, 2021
1 parent 689a676 commit 0b88450
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
14 changes: 14 additions & 0 deletions components/FormikFields/PaperInputPicker/Looper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const Looper = ({
} else {
updatedQuestion.formikKey = `${updatedQuestion.formikKey}__sameForm${individualLoopsAdded}`;
}
if (updatedQuestion.options) {
updatedQuestion.options = updateTextKeys(updatedQuestion.options)
}
updatedQuestions = updatedQuestions.concat(updatedQuestion);
});

Expand All @@ -77,6 +80,17 @@ const Looper = ({
setIndividualLoopsAdded(individualLoopsAdded + 1);
};

const updateTextKeys = (options) => {
let updatedOptions = []
options.forEach((option) => {
const updatedOption = _.cloneDeep(option);
const textKeys = updatedOption.textKey.split("__")
updatedOption.textKey = sameForm ? `__${textKeys[1]}__sameForm${individualLoopsAdded}__${textKeys[2]}` : `__${textKeys[1]}__loop${individualLoopsAdded}__${textKeys[2]}`;
updatedOptions = updatedOptions.concat(updatedOption)
})
return updatedOptions
}

const removeLoop = () => {
if (sameForm !== true) {
setLoopsAdded(loopsAdded - 1);
Expand Down
4 changes: 2 additions & 2 deletions domains/DataCollection/Forms/SupplementaryForm/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ function addSelectTextInputs(values, formObject) {
Object.entries(values).forEach(([key, val]) => {
if (key.slice(0, 2) === '__') {
const keys = key.split('__');
const formikKey = keys[1];
const formikOrigVal = keys[2];
const formikKey = keys[2].includes('sameForm') || keys[2].includes('loop') ? `${keys[1]}__${keys[2]}` : keys[1];
const formikOrigVal = keys[2].includes('sameForm') || keys[2].includes('loop') ? keys[3] : keys[2];
if (typeof (formObject[formikKey]) === 'object') {
const index = newFormObject[formikKey].indexOf(formikOrigVal);
newFormObject[formikKey][index] = `${formikOrigVal}__${val}`;
Expand Down
19 changes: 10 additions & 9 deletions environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ const ENV = {
}
};

const getEnvVars = (env = Constants.manifest.releaseChannel) =>
const getEnvVars = (env = Constants.manifest.releaseChannel) => {
// What is __DEV__ ?
// This variable is set to true when react-native is running in Dev mode.
// __DEV__ is true when run locally, but false when published.
// if (env === null || env === undefined || env === '' || env.indexOf('dev') !== -1) {
// return ENV.dev;
// } if (env.indexOf('staging') !== -1) {
// return ENV.staging;
// } if (env.indexOf('prod') !== -1) {
// return ENV.prod;
// }
ENV.prod;
if (env === null || env === undefined || env === '' || env.indexOf('dev') !== -1) {
return ENV.dev;
} if (env.indexOf('staging') !== -1) {
return ENV.staging;
} if (env.indexOf('prod') !== -1) {
return ENV.prod;
}
// ENV.prod;
}
const selectedENV = getEnvVars();

export default selectedENV;

0 comments on commit 0b88450

Please sign in to comment.