Skip to content

Commit

Permalink
Work with array of values answering choice questions
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rl committed Feb 15, 2024
1 parent 6cc3a9c commit 94c942b
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,19 @@ function ChoiceQuestionSelect(props: ChoiceQuestionSelectProps) {

export function QuestionChoice({ parentPath, questionItem }: QuestionItemProps) {
const { linkId, answerOption, repeats, answerValueSet } = questionItem;
let fieldName = [...parentPath, linkId, 0];

if (repeats) {
fieldName = [...parentPath, linkId];
}
const fieldName = [...parentPath, linkId];

const { value, formItem, onChange } = useFieldController(fieldName, questionItem);

const onSelect = useCallback((option: any) => onChange([].concat(option)), [onChange]);

if (answerValueSet) {
return (
<Form.Item {...formItem} data-testid="question-choice">
<ChoiceQuestionValueSet
answerValueSet={answerValueSet}
value={!repeats && value ? [value] : value}
onChange={onChange}
value={value}
onChange={onSelect}
repeats={repeats}
/>
</Form.Item>
Expand All @@ -69,12 +67,7 @@ export function QuestionChoice({ parentPath, questionItem }: QuestionItemProps)

return (
<Form.Item {...formItem} data-testid="question-choice">
<ChoiceQuestionSelect
options={answerOption!}
value={!repeats && value ? [value] : value}
onChange={onChange}
repeats={repeats}
/>
<ChoiceQuestionSelect options={answerOption!} value={value} onChange={onSelect} repeats={repeats} />
</Form.Item>
);
}
Expand Down

0 comments on commit 94c942b

Please sign in to comment.