mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 09:51:09 +03:00
More accurate survey errors
For the survey question form validation, some errors messages were being thrown for errors that hadn't occured.
This commit is contained in:
parent
397d107380
commit
a2121b7288
@ -63,8 +63,8 @@ export default
|
||||
'user_id<br>host_name<br><div class="popover-footer"><span class="key">esc</span> or click to close</div>" '+
|
||||
'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 && survey_question_form.variable.$error.required">Please enter an answer variable name.</div>'+
|
||||
'<div class="error ng-hide" id="survey_question-variable-variable-error" ng-show="survey_question_form.variable.$dirty && survey_question_form.variable.$error.variable">Please remove the illegal character from the survey question variable name.</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">Please enter an answer variable name.</div>'+
|
||||
'<div class="error ng-hide" id="survey_question-variable-variable-error" ng-show="survey_question_form.variable.$dirty && survey_question_form.variable.$error.variable">Please remove the illegal character from the survey question variable name.</div>'+
|
||||
'<div class="error ng-hide" id=survey_question-variable-duplicate-error" ng-show="duplicate">This question variable is already in use. Please enter a different variable name.</div>' +
|
||||
'<div class="error api-error ng-binding" id="survey_question-variable-api-error" ng-bind="variable_api_error"></div>'+
|
||||
'</div>',
|
||||
@ -106,13 +106,13 @@ export default
|
||||
control:'<div class="row">'+
|
||||
'<div class="col-xs-6">'+
|
||||
'<label for="text_min"><span class="label-text">Minimum Length</span></label><input id="text_min" type="number" name="text_min" ng-model="text_min" min=0 aw-min="0" aw-max="text_max" class="form-control" integer />'+
|
||||
'<div class="error" ng-show="survey_question_form.text_min.$error.number">The minimum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.text_min.$error.integer || survey_question_form.text_min.$error.number">The minimum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.text_min.$error.awMax">The minimium length is too high. Please enter a lower number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.text_min.$error.awMin">The minimum length is too low. Please enter a positive number.</div>'+
|
||||
'</div>'+
|
||||
'<div class="col-xs-6">'+
|
||||
'<label for="text_max"><span class="label-text">Maximum Length</span></label><input id="text_max" type="number" name="text_max" ng-model="text_max" aw-min="text_min || 0" min=0 class="form-control" integer >'+
|
||||
'<div class="error" ng-show="survey_question_form.text_max.$error.number">The maximum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.text_max.$error.integer || survey_question_form.text_max.$error.number">The maximum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.text_max.$error.awMin">The maximum length is too low. Please enter a number larger than the minimum length you set.</div>'+
|
||||
'</div>'+
|
||||
'</div>',
|
||||
@ -127,13 +127,13 @@ export default
|
||||
control:'<div class="row">'+
|
||||
'<div class="col-xs-6">'+
|
||||
'<label for="textarea_min"><span class="label-text">Minimum Length</span></label><input id="textarea_min" type="number" name="textarea_min" ng-model="textarea_min" min=0 aw-min="0" aw-max="textarea_max" class="form-control" integer />'+
|
||||
'<div class="error" ng-show="survey_question_form.textarea_min.$error.number">The minimum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.textarea_min.$error.integer || survey_question_form.textarea_min.$error.number">The minimum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.textarea_min.$error.awMax">The minimium length is too high. Please enter a lower number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.textarea_min.$error.awMin">The minimum length is too low. Please enter a positive number.</div>'+
|
||||
'</div>'+
|
||||
'<div class="col-xs-6">'+
|
||||
'<label for="textarea_max"><span class="label-text">Maximum Length</span></label><input id="textarea_max" type="number" name="textarea_max" ng-model="textarea_max" aw-min="textarea_min || 0" min=0 class="form-control" integer >'+
|
||||
'<div class="error" ng-show="survey_question_form.textarea_max.$error.number">The maximum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.textarea_max.$error.integer || survey_question_form.textarea_max.$error.number">The maximum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.textarea_max.$error.awMin">The maximum length is too low. Please enter a number larger than the minimum length you set.</div>'+
|
||||
'</div>'+
|
||||
'</div>',
|
||||
@ -148,13 +148,13 @@ export default
|
||||
control:'<div class="row">'+
|
||||
'<div class="col-xs-6">'+
|
||||
'<label for="password_min"><span class="label-text">Minimum Length</span></label><input id="password_min" type="number" name="password_min" ng-model="password_min" min=0 aw-min="0" aw-max="password_max" class="form-control" integer />'+
|
||||
'<div class="error" ng-show="survey_question_form.password_min.$error.number">The minimum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.password_min.$error.integer || survey_question_form.password_min.$error.number">The minimum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.password_min.$error.awMax">The minimium length is too high. Please enter a lower number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.password_min.$error.awMin">The minimum length is too low. Please enter a positive number.</div>'+
|
||||
'</div>'+
|
||||
'<div class="col-xs-6">'+
|
||||
'<label for="password_max"><span class="label-text">Maximum Length</span></label><input id="password_max" type="number" name="password_max" ng-model="password_max" aw-min="password_min || 0" min=0 class="form-control" integer >'+
|
||||
'<div class="error" ng-show="survey_question_form.password_max.$error.number">The maximum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.password_max.$error.integer || survey_question_form.password_max.$error.number">The maximum length you entered is not a number. Please enter a number.</div>'+
|
||||
'<div class="error" ng-show="survey_question_form.password_max.$error.awMin">The maximum length is too low. Please enter a number larger than the minimum length you set.</div>'+
|
||||
'</div>'+
|
||||
'</div>',
|
||||
|
@ -70,7 +70,7 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
||||
require: 'ngModel',
|
||||
scope: { ngModel: '=ngModel' },
|
||||
template: '<div class="survey_taker_input" ng-repeat="option in ngModel.options">' +
|
||||
'<label><input type="checkbox" ng-model="cbModel[option.value]" ' +
|
||||
'<label style="font-weight:normal"><input type="checkbox" ng-model="cbModel[option.value]" ' +
|
||||
'value="{{option.value}}" class="mc" ng-change="update(this.value)" />' +
|
||||
'<span>'+
|
||||
'{{option.value}}'+
|
||||
@ -150,7 +150,7 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
||||
var min = (attr.awMin) ? scope.$eval(attr.awMin) : -Infinity;
|
||||
if (!Empty(min) && !Empty(viewValue) && Number(viewValue) < min) {
|
||||
ctrl.$setValidity('awMin', false);
|
||||
return undefined;
|
||||
return viewValue;
|
||||
} else {
|
||||
ctrl.$setValidity('awMin', true);
|
||||
return viewValue;
|
||||
@ -217,17 +217,17 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
||||
if ( elm.attr('min') &&
|
||||
( viewValue === '' || viewValue === null || parseInt(viewValue,10) < parseInt(elm.attr('min'),10) ) ) {
|
||||
ctrl.$setValidity('min', false);
|
||||
return undefined;
|
||||
return viewValue;
|
||||
}
|
||||
if ( elm.attr('max') && ( parseInt(viewValue,10) > parseInt(elm.attr('max'),10) ) ) {
|
||||
ctrl.$setValidity('max', false);
|
||||
return undefined;
|
||||
return viewValue;
|
||||
}
|
||||
return viewValue;
|
||||
}
|
||||
// Invalid, return undefined (no model update)
|
||||
ctrl.$setValidity('integer', false);
|
||||
return undefined;
|
||||
return viewValue;
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -238,15 +238,24 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
||||
.directive('awSurveyVariableName', function() {
|
||||
var FLOAT_REGEXP = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
|
||||
return {
|
||||
restrict: 'A',
|
||||
require: 'ngModel',
|
||||
link: function(scope, elm, attrs, ctrl) {
|
||||
ctrl.$setValidity('required', true); // we only want the error message for incorrect characters to be displayed
|
||||
ctrl.$parsers.unshift(function(viewValue) {
|
||||
if(viewValue.length !== 0){
|
||||
if (FLOAT_REGEXP.test(viewValue) && viewValue.indexOf(' ') === -1) { //check for a spaces
|
||||
ctrl.$setValidity('variable', true);
|
||||
return viewValue;
|
||||
} else {
|
||||
ctrl.$setValidity('variable', false); // spaces found, therefore throw error
|
||||
return undefined;
|
||||
}
|
||||
else{
|
||||
ctrl.$setValidity('variable', false); // spaces found, therefore throw error.
|
||||
return viewValue;
|
||||
}
|
||||
}
|
||||
else{
|
||||
ctrl.$setValidity('variable', true); // spaces found, therefore throw error.
|
||||
return viewValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user