mirror of
https://github.com/ansible/awx.git
synced 2026-03-10 22:19:28 -02:30
Survey maker variable name checking
Generalized the directive for the variable name of survey maker to check for illegal characters for a javascript object
This commit is contained in:
@@ -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"><i class="fa fa-question-circle"></i></a> </label>'+
|
'data-placement="right" data-container="body" data-title="Answer Variable Name" class="help-link" data-original-title="" title="" tabindex="-1"><i class="fa fa-question-circle"></i></a> </label>'+
|
||||||
'<div><input type="text" ng-model="variable" name="variable" id="survey_question_variable" class="form-control ng-pristine ng-invalid ng-invalid-required" required="" aw-survey-variable-name>'+
|
'<div><input type="text" ng-model="variable" name="variable" id="survey_question_variable" class="form-control ng-pristine ng-invalid ng-invalid-required" required="" aw-survey-variable-name>'+
|
||||||
'<div class="error ng-hide" id="survey_question-variable-required-error" ng-show="survey_question_form.variable.$dirty && survey_question_form.variable.$error.required">A value is required!</div>'+
|
'<div class="error ng-hide" id="survey_question-variable-required-error" ng-show="survey_question_form.variable.$dirty && survey_question_form.variable.$error.required">A value is required!</div>'+
|
||||||
'<div class="error ng-hide" id="survey_question-variable-required-error" ng-show="survey_question_form.variable.$dirty && survey_question_form.variable.$error.variable">Please remove spaces</div>'+
|
'<div class="error ng-hide" id="survey_question-variable-required-error" ng-show="survey_question_form.variable.$dirty && survey_question_form.variable.$error.variable">The value contains an illegal character!</div>'+
|
||||||
'<div class="error api-error ng-binding" id="survey_question-variable-api-error" ng-bind="variable_api_error"></div>'+
|
'<div class="error api-error ng-binding" id="survey_question-variable-api-error" ng-bind="variable_api_error"></div>'+
|
||||||
'</div>',
|
'</div>',
|
||||||
addRequired: true,
|
addRequired: true,
|
||||||
|
|||||||
@@ -397,10 +397,6 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
|
|||||||
scope.float_min = null;
|
scope.float_min = null;
|
||||||
scope.float_max = null;
|
scope.float_max = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (scope.removeFillQuestionForm) {
|
if (scope.removeFillQuestionForm) {
|
||||||
scope.removeFillQuestionForm();
|
scope.removeFillQuestionForm();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,16 +239,16 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
//the awSurveyVariableName directive checks if the field contains any spaces.
|
//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
|
// this could be elaborated in the future for other things we want to check this field against
|
||||||
.directive('awSurveyVariableName', function() {
|
.directive('awSurveyVariableName', function() {
|
||||||
// var FLOAT_REGEXP = /^\-?\d+((\.|\,)\d+)?$/;
|
var FLOAT_REGEXP = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
ctrl.$parsers.unshift(function(viewValue) {
|
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);
|
ctrl.$setValidity('variable', true);
|
||||||
return viewValue;
|
return viewValue;
|
||||||
} else {
|
} else {
|
||||||
ctrl.$setValidity('variable', false);
|
ctrl.$setValidity('variable', false); // spaces found, therefore throw error
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user