Skip to content

Commit

Permalink
🐛 Fully unique ids for answer selections
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <[email protected]>
  • Loading branch information
ibolton336 committed Sep 21, 2023
1 parent bac5ce1 commit 334a6f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ export const MultiInputSelection: React.FC<MultiInputSelectionProps> = ({

const isArchetype = useIsArchetype();
const { t } = useTranslation();

return (
<Stack>
{sortedOptions.map((option, i) => (
<StackItem key={option.text} className="pf-v5-u-pb-xs">
<StackItem key={`${questionFieldName}-${i}`} className="pf-v5-u-pb-xs">
<HookFormPFGroupController
control={control}
name={questionFieldName as `questions.${string}`}
fieldId="stakeholders"
fieldId={`${questionFieldName}-${i}`}
renderInput={({ field: { value, onChange } }) => (
<Radio
id={`${option.text}`}
id={`${questionFieldName}-${option.order}`}
name={questionFieldName}
isChecked={value === option.text}
onChange={(checked, e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import HelpIcon from "@patternfly/react-icons/dist/esm/icons/help-icon";
import { MultiInputSelection } from "./multi-input-selection";
import { Question, QuestionHeader, QuestionBody } from "./question";
import { getCommentFieldName } from "../../form-utils";
import { getCommentFieldName, getQuestionFieldName } from "../../form-utils";
import { HookFormPFTextInput } from "@app/components/HookFormPFFields";
import { useFormContext } from "react-hook-form";
import { Section } from "@app/api/models";
Expand Down Expand Up @@ -54,7 +54,7 @@ export const QuestionnaireForm: React.FC<QuestionnaireFormProps> = ({
</TextContent>
</StackItem>
{sortedQuestions.map((question) => (
<StackItem key={question.text}>
<StackItem key={question.order}>
<Question cy-data="question">
<QuestionHeader>
<Split hasGutter>
Expand All @@ -74,7 +74,10 @@ export const QuestionnaireForm: React.FC<QuestionnaireFormProps> = ({
</Split>
</QuestionHeader>
<QuestionBody>
<MultiInputSelection question={question} />
<MultiInputSelection
key={getQuestionFieldName(question, true)}
question={question}
/>
</QuestionBody>
</Question>
</StackItem>
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/pages/assessment/form-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const getCommentFieldName = (section: Section, fullName: boolean) => {
};

export const getQuestionFieldName = (question: Question, fullName: boolean) => {
const fieldName = `question-${question.text}`;
const fieldName = `question-${question.order}`;
return fullName ? `${QUESTIONS_KEY}.${fieldName}` : fieldName;
};

0 comments on commit 334a6f9

Please sign in to comment.