Skip to content

Commit

Permalink
feat: textInput with selects works 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Nov 11, 2020
1 parent 514cce4 commit 8b4726f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
25 changes: 13 additions & 12 deletions domains/DataCollection/Forms/SupplementaryForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import medConfig from './configs/medical-evaluation.config';
import I18n from '../../../../modules/i18n';
import PaperInputPicker from '../../../../components/FormikFields/PaperInputPicker';
import yupValidationPicker from '../../../../components/FormikFields/YupValidation';
import addSelectTextInputs from './utils';

const SupplementaryForm = ({
navigation, selectedForm, setSelectedForm, surveyee, surveyingUser, surveyingOrganization,
Expand Down Expand Up @@ -51,18 +52,20 @@ const SupplementaryForm = ({
formObject.surveyingUser = surveyingUser;
formObject.surveyingOrganization = surveyingOrganization;

const formObjectUpdated = addSelectTextInputs(values, formObject);

const postParams = {
parseParentClassID: surveyee.objectId,
parseParentClass: 'SurveyData',
parseClass: config.class,
photoFile,
localObject: formObject
localObject: formObjectUpdated
};

if (selectedForm === 'custom') {
postParams.parseClass = 'FormResults';

const fieldsArray = Object.entries(formObject).map((obj) => ({
const fieldsArray = Object.entries(formObjectUpdated).map((obj) => ({
title: obj[0],
answer: obj[1]
}));
Expand All @@ -83,8 +86,6 @@ const SupplementaryForm = ({
});
}}
validationSchema={validationSchema}
// validateOnBlur={false}
// validateOnChange={false}
>
{(formikProps) => (
<View style={layout.formContainer}>
Expand All @@ -101,14 +102,14 @@ const SupplementaryForm = ({
{formikProps.isSubmitting ? (
<ActivityIndicator />
) : (
<Button
disabled={!surveyee.objectId}
onPress={formikProps.handleSubmit}
>
{surveyee.objectId && <Text>{I18n.t('global.submit')}</Text>}
{!surveyee.objectId && <Text>{I18n.t('supplementaryForms.attachResident')}</Text>}
</Button>
)}
<Button
disabled={!surveyee.objectId}
onPress={formikProps.handleSubmit}
>
{surveyee.objectId && <Text>{I18n.t('global.submit')}</Text>}
{!surveyee.objectId && <Text>{I18n.t('supplementaryForms.attachResident')}</Text>}
</Button>
)}
</View>
)}
</Formik>
Expand Down
15 changes: 15 additions & 0 deletions domains/DataCollection/Forms/SupplementaryForm/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function addSelectTextInputs(values, formObject) {
Object.entries(values).forEach(([key, val]) => {
if (key.slice(0, 2) === '__') {
let keys = key.split("__")
const formikKey = keys[1];
const formikOrigVal = keys[2];
const index = formObject[formikKey].indexOf(formikOrigVal)
formObject[formikKey][index] = formikOrigVal + "__" + val;
delete formObject[key];
}
})
return formObject;
}

export default addSelectTextInputs;

0 comments on commit 8b4726f

Please sign in to comment.