Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Created June 23, 2016 15:15
Show Gist options
  • Select an option

  • Save aaronmcadam/d25c5a11b513541bb8a21f8b77cabc6c to your computer and use it in GitHub Desktop.

Select an option

Save aaronmcadam/d25c5a11b513541bb8a21f8b77cabc6c to your computer and use it in GitHub Desktop.
const MultiCode = ({ interview, options, dispatchChange }) => {
const currentOptions = () => (
getCurrentOptions(interview.selections.value, options)
);
const addValues = (selectedOptions) => {
dispatchChange(selectedOptions.map(option => ({ optionId: option.id })));
};
const updateForm = (optionIsSelected, option) => {
const selectedOptions = mapOptions(
currentOptions(),
option,
!optionIsSelected
);
addValues(selectedOptions);
};
const isDisabled = (option) => (
isOptionDisabled(option, currentOptions())
);
const isChecked = (option) => (
isOptionChecked(option, currentOptions())
);
return (
<div className="coded-questions">
<QuestionErrorMessage element={interview.selections} />
{options.map(option => (
<MultiCodeOption
key={option.id}
option={option}
onOptionChange={updateForm}
isChecked={isChecked(option)}
isDisabled={isDisabled(option)}
/>
))}
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment