From e9e2c1f6ab3c32811f9cd7d78498ccca6184f061 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Tue, 2 Dec 2014 12:44:16 -0500 Subject: [PATCH] awSurveyVariableName directive created a new directive to check the variable name field for spaces. this could be expanded for future use if we want to check against other constraints. checked with matt though and he said space checking shoudl suffice --- awx/ui/static/js/forms/SurveyQuestion.js | 25 ++++++++++++++++++++++-- awx/ui/static/lib/ansible/directives.js | 20 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/awx/ui/static/js/forms/SurveyQuestion.js b/awx/ui/static/js/forms/SurveyQuestion.js index b798b94cb3..5ce04d99bc 100644 --- a/awx/ui/static/js/forms/SurveyQuestion.js +++ b/awx/ui/static/js/forms/SurveyQuestion.js @@ -41,9 +41,30 @@ angular.module('SurveyQuestionFormDefinition', []) editRequired: false, column: 1 }, + // variable: { + // label: 'Answer Variable Name', + // type: 'text', + // addRequired: true, + // editRequired: true, + // column: 1, + // awPopOver: '

The suggested format for variable names are lowercase, underscore-seperated descriptive nouns.

'+ + // '

For example:
foo_bar
\n user_id
\n host_name
' , + // dataTitle: 'Answer Variable Name', + // dataPlacement: 'right', + // dataContainer: "body" + // }, variable: { - label: 'Answer Variable Name', - type: 'text', + ealName: 'variable', + type: 'custom', + control:''+ + '

'+ + '
A value is required!
'+ + '
Please remove spaces
'+ + '
'+ + '
', addRequired: true, editRequired: true, column: 1 diff --git a/awx/ui/static/lib/ansible/directives.js b/awx/ui/static/lib/ansible/directives.js index d98c9e9cf3..8282a43944 100644 --- a/awx/ui/static/lib/ansible/directives.js +++ b/awx/ui/static/lib/ansible/directives.js @@ -236,6 +236,26 @@ 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+)?$/; + return { + require: 'ngModel', + link: function(scope, elm, attrs, ctrl) { + ctrl.$parsers.unshift(function(viewValue) { + if (viewValue.indexOf(' ') === -1) { + ctrl.$setValidity('variable', true); + return viewValue; + } else { + ctrl.$setValidity('variable', false); + return undefined; + } + }); + } + }; + }) + // // awRequiredWhen: { variable: "", init:"true|false" } //