diff --git a/awx/ui_next/src/components/LaunchPrompt/getSurveyValues.js b/awx/ui_next/src/components/LaunchPrompt/getSurveyValues.js index 0559eefc1f..17b9fd1aed 100644 --- a/awx/ui_next/src/components/LaunchPrompt/getSurveyValues.js +++ b/awx/ui_next/src/components/LaunchPrompt/getSurveyValues.js @@ -1,7 +1,10 @@ export default function getSurveyValues(values) { const surveyValues = {}; Object.keys(values).forEach(key => { - if (key.startsWith('survey_')) { + if (key.startsWith('survey_') && values[key] !== []) { + if (Array.isArray(values[key]) && values[key].length === 0) { + return; + } surveyValues[key.substr(7)] = values[key]; } }); diff --git a/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx b/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx index 14e26f4d10..bc94fea258 100644 --- a/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx @@ -48,7 +48,7 @@ function PreviewStep({ resource, config, survey, formErrors, i18n }) { return ( - {formErrors.length > 0 && ( + {formErrors && ( {i18n._(t`Some of the previous step(s) have errors`)} { extra_vars: 'one: 1', }); }); + + test('should remove survey with empty array value', async () => { + let wrapper; + await act(async () => { + wrapper = mountWithContexts( + + + + ); + }); + + const detail = wrapper.find('PromptDetail'); + expect(detail).toHaveLength(1); + expect(detail.prop('resource')).toEqual(resource); + expect(detail.prop('overrides')).toEqual({ + extra_vars: 'one: 1', + }); + }); }); diff --git a/awx/ui_next/src/components/LaunchPrompt/steps/SurveyStep.jsx b/awx/ui_next/src/components/LaunchPrompt/steps/SurveyStep.jsx index 1d5906de5d..d5f4a42df4 100644 --- a/awx/ui_next/src/components/LaunchPrompt/steps/SurveyStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/steps/SurveyStep.jsx @@ -146,9 +146,14 @@ function MultiSelectField({ question, i18n }) { } else { helpers.setValue(field.value.concat(option)); } + helpers.setTouched(true); }} isOpen={isOpen} selections={field.value} + onClear={() => { + helpers.setTouched(true); + helpers.setValue([]); + }} > {question.choices.split('\n').map(opt => ( diff --git a/awx/ui_next/src/components/LaunchPrompt/steps/useSurveyStep.jsx b/awx/ui_next/src/components/LaunchPrompt/steps/useSurveyStep.jsx index 7c150117e0..7137536f09 100644 --- a/awx/ui_next/src/components/LaunchPrompt/steps/useSurveyStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/steps/useSurveyStep.jsx @@ -45,15 +45,9 @@ export default function useSurveyStep(config, visitedSteps, i18n) { }); return errors; }; - const formError = validate(); + const formError = Object.keys(validate()).length > 0; return { - step: getStep( - config, - survey, - Object.keys(formError).length > 0, - i18n, - visitedSteps - ), + step: getStep(config, survey, formError, i18n, visitedSteps), formError, initialValues: getInitialValues(config, survey), survey,