From 83046aeef7c19cc0afe4c6d9e8b00d65c953ba30 Mon Sep 17 00:00:00 2001 From: Joe Fiorini Date: Wed, 12 Aug 2015 14:01:48 -0400 Subject: [PATCH] Include empty values for blank, optional select lists --- awx/ui/client/src/helpers/JobSubmission.js | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/helpers/JobSubmission.js b/awx/ui/client/src/helpers/JobSubmission.js index d461d6a659..9e641dc388 100644 --- a/awx/ui/client/src/helpers/JobSubmission.js +++ b/awx/ui/client/src/helpers/JobSubmission.js @@ -154,9 +154,31 @@ function(Rest, Wait, ProcessErrors, ToJSON, Empty, GetBasePath) { if(scope.survey_questions[i].required || (scope.survey_questions[i].required === false && scope[fld].toString()!=="")) { job_launch_data.extra_vars[fld] = scope[fld]; } - // for optional text and text-areas, submit a blank string if min length is 0 - if(scope.survey_questions[i].required === false && (scope.survey_questions[i].type === "text" || scope.survey_questions[i].type === "textarea") && scope.survey_questions[i].min === 0 && (scope[fld] === "" || scope[fld] === undefined)){ - job_launch_data.extra_vars[fld] = ""; + + + if(scope.survey_questions[i].required === false && _.isEmpty(scope[fld])) { + switch (scope.survey_questions[i].type) { + // for optional text and text-areas, submit a blank string if min length is 0 + // -- this is confusing, for an explanation see: + // http://docs.ansible.com/ansible-tower/latest/html/userguide/job_templates.html#optional-survey-questions + // + case "text": + case "textarea": + if (scope.survey_questions[i].min === 0) { + job_launch_data.extra_vars[fld] = ""; + } + break; + + // for optional select lists, if they are left blank make sure we submit + // a value that the API will consider "empty" + // + case "multiplechoice": + job_launch_data.extra_vars[fld] = ""; + break; + case "multiselect": + job_launch_data.extra_vars[fld] = []; + break; + } } } }