Skip to content

Commit

Permalink
Fix questions step could be skipped when selecting others
Browse files Browse the repository at this point in the history
closes #861
  • Loading branch information
elboletaire committed Jan 23, 2025
1 parent be7373c commit b58fc04
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/components/ProcessCreate/StepForm/Questions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@ export interface QuestionsValues {
const QuestionsTabs = () => {
const { t } = useTranslation()
const { form, setForm } = useProcessCreationSteps()

const definedVotingTypes = useVotingType()
const unDefinedVotingTypes = useUnimplementedVotingType()
const { questionType } = form

const { watch } = useFormContext()

const {
watch,
register,
setValue,
trigger,
formState: { errors },
} = useFormContext()
const { replace } = useFieldArray({
name: `questions`,
})

const definedVotingTypes = useVotingType()
const unDefinedVotingTypes = useUnimplementedVotingType()
const questions = watch('questions')

// required in order to force users to select a type, although the error is not visible
register('questionType', { required: t('form.error.field_is_required') })

return (
<TabsPage
definedList={definedVotingTypes}
Expand All @@ -48,6 +52,10 @@ const QuestionsTabs = () => {
if (newQuestionType && !MultiQuestionTypes.includes(newQuestionType) && questions.length > 1) {
replace(questions[0])
}

setValue('questionType', newQuestionType, { shouldValidate: true })
trigger('questionType')

const nform: StepsFormValues = {
...form,
questionType: newQuestionType,
Expand All @@ -56,7 +64,7 @@ const QuestionsTabs = () => {
}}
title={t('process_create.question.voting_type.title')}
description={t('process_create.question.voting_type.description')}
selected={questionType}
selected={form.questionType}
/>
)
}
Expand Down

2 comments on commit b58fc04

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.