From adaa24a5624be6e3deef51a73bb9ad94cc922f59 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 28 Sep 2021 10:37:44 -0400 Subject: [PATCH] Properly validates Integer Survey Question with min value of 0 --- .../src/components/LaunchPrompt/steps/useSurveyStep.js | 9 ++++++--- awx/ui/src/screens/Template/Survey/SurveyQuestionForm.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/awx/ui/src/components/LaunchPrompt/steps/useSurveyStep.js b/awx/ui/src/components/LaunchPrompt/steps/useSurveyStep.js index 1fbe49e0f4..19484747fa 100644 --- a/awx/ui/src/components/LaunchPrompt/steps/useSurveyStep.js +++ b/awx/ui/src/components/LaunchPrompt/steps/useSurveyStep.js @@ -72,7 +72,7 @@ function getInitialValues(launchConfig, surveyConfig, resource) { ? question.default.split('\n') : []; } else { - values[`survey_${question.variable}`] = question.default || ''; + values[`survey_${question.variable}`] = question.default ?? ''; } if (resource?.extra_data) { Object.entries(resource.extra_data).forEach(([key, value]) => { @@ -129,11 +129,14 @@ function checkForError(launchConfig, surveyConfig, values) { } } if (isNumeric && (value || value === 0)) { - if (value < question.min || value > question.max) { + if ( + (value < question.min || value > question.max) && + question.required + ) { hasError = true; } } - if (question.required && (!value || value.length === 0)) { + if (question.required && (!value || value.length === 0) && !isNumeric) { hasError = true; } }); diff --git a/awx/ui/src/screens/Template/Survey/SurveyQuestionForm.js b/awx/ui/src/screens/Template/Survey/SurveyQuestionForm.js index f801b21b6c..300479c2da 100644 --- a/awx/ui/src/screens/Template/Survey/SurveyQuestionForm.js +++ b/awx/ui/src/screens/Template/Survey/SurveyQuestionForm.js @@ -114,7 +114,7 @@ function SurveyQuestionForm({ variable: question?.variable || '', min: question?.min || 0, max: question?.max || 1024, - default: question?.default || '', + default: question?.default ?? '', choices: question?.choices || '', formattedChoices: [{ choice: '', isDefault: false, id: 0 }], new_question: !question,