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:
Jared Tabor 2014-12-15 11:27:00 -05:00
parent a487257789
commit 651dd1239a
3 changed files with 4 additions and 8 deletions

View File

@ -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>'+
'<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 &amp;&amp; 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 &amp;&amp; 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 &amp;&amp; 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>',
addRequired: true,

View File

@ -397,10 +397,6 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper',
scope.float_min = null;
scope.float_max = null;
if (scope.removeFillQuestionForm) {
scope.removeFillQuestionForm();
}

View File

@ -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;
}
});