diff --git a/awx/ui/client/features/templates/templates.strings.js b/awx/ui/client/features/templates/templates.strings.js index 515673e003..6f338c873f 100644 --- a/awx/ui/client/features/templates/templates.strings.js +++ b/awx/ui/client/features/templates/templates.strings.js @@ -51,6 +51,7 @@ function TemplatesStrings (BaseString) { CHOOSE_VERBOSITY: t.s('Choose a verbosity'), EXTRA_VARIABLES: t.s('Extra Variables'), PLEASE_ENTER_ANSWER: t.s('Please enter an answer.'), + PLEASE_SELECT_VALUE: t.s('Please select a value'), VALID_INTEGER: t.s('Please enter an answer that is a valid integer.'), VALID_DECIMAL: t.s('Please enter an answer that is a decimal number.'), PLAYBOOK_RUN: t.s('Playbook Run'), diff --git a/awx/ui/client/src/shared/directives.js b/awx/ui/client/src/shared/directives.js index 59d3029ebe..400a967584 100644 --- a/awx/ui/client/src/shared/directives.js +++ b/awx/ui/client/src/shared/directives.js @@ -1247,31 +1247,29 @@ function(ConfigurationUtils, i18n, $rootScope) { }; }]) -.directive('awRequireMultiple', [function() { +.directive('awRequireMultiple', ['Empty', function(Empty) { return { require: 'ngModel', link: function postLink(scope, element, attrs, ngModel) { // Watch for changes to the required attribute - attrs.$observe('required', function(value) { - if(value) { - ngModel.$validators.required = function (value) { - if(angular.isArray(value)) { - if(value.length === 0) { - return false; - } - else { - return (!value[0] || value[0] === "") ? false : true; - } - } - else { - return (!value || value === "") ? false : true; - } - }; - } - else { - delete ngModel.$validators.required; - } + attrs.$observe('required', function() { + ngModel.$validate(); }); + + ngModel.$validators.multipleSelect = function (modelValue) { + if(attrs.required) { + if(angular.isArray(modelValue)) { + // Checks to make sure at least one value in the array + return _.some(modelValue, function(arrayVal) { + return !Empty(arrayVal); + }); + } else { + return !Empty(modelValue); + } + } else { + return true; + } + }; } }; }]); diff --git a/awx/ui/client/src/templates/prompt/steps/survey/prompt-survey.partial.html b/awx/ui/client/src/templates/prompt/steps/survey/prompt-survey.partial.html index 8ff7aeba52..73d23c6f81 100644 --- a/awx/ui/client/src/templates/prompt/steps/survey/prompt-survey.partial.html +++ b/awx/ui/client/src/templates/prompt/steps/survey/prompt-survey.partial.html @@ -10,13 +10,13 @@
-
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
-
Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.
+
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
+
Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.
-
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
-
Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.
+
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
+
Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.
@@ -26,20 +26,20 @@
-
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
-
Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.
+
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
+
Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.
-
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
-
{{:: vm.strings.get('prompt.VALID_INTEGER') }}
-
Please enter an answer between {{question.minValue}} and {{question.maxValue}}.
+
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
+
{{:: vm.strings.get('prompt.VALID_INTEGER') }}
+
Please enter an answer between {{question.minValue}} and {{question.maxValue}}.
-
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
-
{{:: vm.strings.get('prompt.VALID_DECIMAL') }}
-
Please enter an answer between {{question.minValue}} and {{question.maxValue}}.
+
{{:: vm.strings.get('prompt.PLEASE_ENTER_ANSWER') }}
+
{{:: vm.strings.get('prompt.VALID_DECIMAL') }}
+
Please enter an answer between {{question.minValue}} and {{question.maxValue}}.
@@ -48,9 +48,11 @@ question="question" choices="question.choices" ng-required="question.required" - ng-model="question.model"> + ng-model="question.model" + form-element-name="survey_question_{{$index}}">
+
{{:: vm.strings.get('prompt.PLEASE_SELECT_VALUE') }}
+ ng-model="question.model" + form-element-name="survey_question_{{$index}}"> +
{{:: vm.strings.get('prompt.PLEASE_SELECT_VALUE') }}
diff --git a/awx/ui/client/src/templates/survey-maker/render/multiple-choice.directive.js b/awx/ui/client/src/templates/survey-maker/render/multiple-choice.directive.js index 9eccb7c195..c55231f24e 100644 --- a/awx/ui/client/src/templates/survey-maker/render/multiple-choice.directive.js +++ b/awx/ui/client/src/templates/survey-maker/render/multiple-choice.directive.js @@ -36,7 +36,8 @@ export default isRequired: '=ngRequired', selectedValue: '=ngModel', isDisabled: '=ngDisabled', - preview: '=' + preview: '=', + formElementName: '@' }, templateUrl: templateUrl('templates/survey-maker/render/multiple-choice'), link: _.partial(link, $timeout, CreateSelect2) diff --git a/awx/ui/client/src/templates/survey-maker/render/multiple-choice.partial.html b/awx/ui/client/src/templates/survey-maker/render/multiple-choice.partial.html index 7fa7e1fa0d..a29362e7ec 100644 --- a/awx/ui/client/src/templates/survey-maker/render/multiple-choice.partial.html +++ b/awx/ui/client/src/templates/survey-maker/render/multiple-choice.partial.html @@ -1,5 +1,5 @@
-