Merge pull request #10335 from mabashian/10129-multi-choice-survey

Properly validate multiple choice survey questions

SUMMARY
link #10129
In action:

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

UI

Reviewed-by: Kersom <None>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-06-02 20:41:20 +00:00 committed by GitHub
commit 49eccfb19f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -92,7 +92,10 @@ function NumberField({ question }) {
}
function MultipleChoiceField({ question }) {
const [field, meta] = useField(`survey_${question.variable}`);
const [field, meta] = useField({
name: `survey_${question.variable}`,
validate: question.required ? required(null) : null,
});
const id = `survey-question-${question.variable}`;
const isValid = !(meta.touched && meta.error);
return (

View File

@ -10,7 +10,6 @@ export default function useSurveyStep(
launchConfig,
surveyConfig,
resource,
visitedSteps
) {
const { setFieldError, values } = useFormikContext();
@ -137,7 +136,7 @@ function checkForError(launchConfig, surveyConfig, values) {
hasError = true;
}
}
if (question.required && !value && value !== 0) {
if (question.required && (!value || value.length === 0)) {
hasError = true;
}
});