From 651dd1239a9bccef42da311ab8a52d409b0de01b Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Mon, 15 Dec 2014 11:27:00 -0500 Subject: [PATCH] Survey maker variable name checking Generalized the directive for the variable name of survey maker to check for illegal characters for a javascript object --- awx/ui/static/js/forms/SurveyQuestion.js | 2 +- awx/ui/static/js/helpers/Survey.js | 4 ---- awx/ui/static/lib/ansible/directives.js | 6 +++--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/awx/ui/static/js/forms/SurveyQuestion.js b/awx/ui/static/js/forms/SurveyQuestion.js index f429852fac..89c4a59dfb 100644 --- a/awx/ui/static/js/forms/SurveyQuestion.js +++ b/awx/ui/static/js/forms/SurveyQuestion.js @@ -62,7 +62,7 @@ angular.module('SurveyQuestionFormDefinition', []) 'data-placement="right" data-container="body" data-title="Answer Variable Name" class="help-link" data-original-title="" title="" tabindex="-1"> '+ '
'+ '
A value is required!
'+ - '
Please remove spaces
'+ + '
The value contains an illegal character!
'+ '
'+ '
', addRequired: true, diff --git a/awx/ui/static/js/helpers/Survey.js b/awx/ui/static/js/helpers/Survey.js index 17fabdf65e..0801ae512e 100644 --- a/awx/ui/static/js/helpers/Survey.js +++ b/awx/ui/static/js/helpers/Survey.js @@ -397,10 +397,6 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', scope.float_min = null; scope.float_max = null; - - - - if (scope.removeFillQuestionForm) { scope.removeFillQuestionForm(); } diff --git a/awx/ui/static/lib/ansible/directives.js b/awx/ui/static/lib/ansible/directives.js index 8282a43944..1cef146fd8 100644 --- a/awx/ui/static/lib/ansible/directives.js +++ b/awx/ui/static/lib/ansible/directives.js @@ -239,16 +239,16 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job //the awSurveyVariableName directive checks if the field contains any spaces. // this could be elaborated in the future for other things we want to check this field against .directive('awSurveyVariableName', function() { - // var FLOAT_REGEXP = /^\-?\d+((\.|\,)\d+)?$/; + var FLOAT_REGEXP = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/; return { require: 'ngModel', link: function(scope, elm, attrs, ctrl) { ctrl.$parsers.unshift(function(viewValue) { - if (viewValue.indexOf(' ') === -1) { + if (FLOAT_REGEXP.test(viewValue) && viewValue.indexOf(' ') === -1) { //check for a spaces ctrl.$setValidity('variable', true); return viewValue; } else { - ctrl.$setValidity('variable', false); + ctrl.$setValidity('variable', false); // spaces found, therefore throw error return undefined; } });