From 0cadea1cb547182163428b4944dc037dc69810e2 Mon Sep 17 00:00:00 2001 From: mabashian Date: Wed, 21 Mar 2018 14:55:38 -0400 Subject: [PATCH 1/2] Fixed bug preventing the user from ignoring a non-required multi-select survey question on launch --- awx/ui/client/src/shared/directives.js | 33 +++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/awx/ui/client/src/shared/directives.js b/awx/ui/client/src/shared/directives.js index 59d3029ebe..f63ed7ed76 100644 --- a/awx/ui/client/src/shared/directives.js +++ b/awx/ui/client/src/shared/directives.js @@ -1252,26 +1252,27 @@ function(ConfigurationUtils, i18n, $rootScope) { 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; - } + attrs.$observe('required', function() { + ngModel.$validate(); + }); + + ngModel.$validators.required = function (value) { + if(attrs.required) { + if(angular.isArray(value)) { + if(value.length === 0) { + return false; } else { - return (!value || value === "") ? false : true; + return (!value[0] || value[0] === "") ? false : true; } - }; + } + else { + return (!value || value === "") ? false : true; + } + } else { + return true; } - else { - delete ngModel.$validators.required; - } - }); + }; } }; }]); From c3b32e2a73334e80f84f5d56a8913f4ec9512018 Mon Sep 17 00:00:00 2001 From: mabashian Date: Thu, 22 Mar 2018 11:58:47 -0400 Subject: [PATCH 2/2] Cleaned up awRequireMultiple and fixed broken survey question error messaging --- .../features/templates/templates.strings.js | 1 + awx/ui/client/src/shared/directives.js | 21 ++++++------ .../steps/survey/prompt-survey.partial.html | 32 +++++++++++-------- .../render/multiple-choice.directive.js | 3 +- .../render/multiple-choice.partial.html | 2 +- 5 files changed, 31 insertions(+), 28 deletions(-) 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 f63ed7ed76..400a967584 100644 --- a/awx/ui/client/src/shared/directives.js +++ b/awx/ui/client/src/shared/directives.js @@ -1247,7 +1247,7 @@ function(ConfigurationUtils, i18n, $rootScope) { }; }]) -.directive('awRequireMultiple', [function() { +.directive('awRequireMultiple', ['Empty', function(Empty) { return { require: 'ngModel', link: function postLink(scope, element, attrs, ngModel) { @@ -1256,18 +1256,15 @@ function(ConfigurationUtils, i18n, $rootScope) { ngModel.$validate(); }); - ngModel.$validators.required = function (value) { + ngModel.$validators.multipleSelect = function (modelValue) { if(attrs.required) { - if(angular.isArray(value)) { - if(value.length === 0) { - return false; - } - else { - return (!value[0] || value[0] === "") ? false : true; - } - } - else { - return (!value || value === "") ? false : true; + 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 @@
-