mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 05:55:59 -03:30
ngMin/ngMax directives fix for surveys
the ngMin and ngMax directives needed to be re-written to work properly with other directives. They weren't playing nice with other directives' values
This commit is contained in:
@@ -517,9 +517,9 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
||||
if(question.type === 'integer'){
|
||||
min = (!Empty(question.min)) ? Number(question.min) : "";
|
||||
max = (!Empty(question.max)) ? Number(question.max) : "" ;
|
||||
html+='<input type="number" id="'+question.variable+'" ng-model="'+question.variable+'" class="form-control" name="'+question.variable+'" ng-required="'+question.required+'" integer />'+
|
||||
html+='<input type="number" id="'+question.variable+'" ng-model="'+question.variable+'" class="form-control" name="'+question.variable+'" ng-required="'+question.required+'" integer ng-min="'+min+'" ng-max="'+max+'" />'+
|
||||
'<div class="error survey_error" ng-show="job_launch_form.'+ question.variable + '.$dirty && job_launch_form.'+question.variable+'.$error.required">A value is required!</div>'+
|
||||
'<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$dirty && (job_launch_form.'+question.variable+'.$error.number || job_launch_form.'+question.variable+'.$error.integer)" >This is not valid integer!</div>'+
|
||||
'<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.number || job_launch_form.'+question.variable+'.$error.integer" >This is not valid integer!</div>'+
|
||||
'<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.ngMin || job_launch_form.'+question.variable+'.$error.ngMax"> The value must be in range {{'+min+'}} to {{'+max+'}}!</div>';
|
||||
|
||||
}
|
||||
@@ -528,7 +528,7 @@ function($location, Wait, GetBasePath, LookUpInit, JobTemplateForm, CredentialLi
|
||||
min = (!Empty(question.min)) ? question.min : "";
|
||||
max = (!Empty(question.max)) ? question.max : "" ;
|
||||
defaultValue = (!Empty(question.default)) ? question.default : (!Empty(question.default_float)) ? question.default_float : "" ;
|
||||
html+='<input type="number" id="'+question.variable+'" ng-model="'+question.variable+'" class=" form-control" name="'+question.variable+'" ng-required="'+question.variable+'" smart-float />'+
|
||||
html+='<input type="number" id="'+question.variable+'" ng-model="'+question.variable+'" class=" form-control" name="'+question.variable+'" ng-required="'+question.variable+'" smart-float ng-min="'+min+'" ng-max="'+max+'"/>'+
|
||||
'<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.number || job_launch_form.'+question.variable+'.$error.float">This is not valid float!</div>'+
|
||||
'<div class="error survey_error" ng-show="job_launch_form.'+question.variable+'.$error.ngMin || job_launch_form.'+question.variable+'.$error.ngMax"> The value must be in range {{'+min+'}} to {{'+max+'}}!</div>';
|
||||
}
|
||||
|
||||
@@ -148,23 +148,17 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
||||
return {
|
||||
restrict: 'A',
|
||||
require: 'ngModel',
|
||||
// scope: true,
|
||||
link: function (scope, elem, attr, ctrl) {
|
||||
scope.$watch(attr.ngMin, function () {
|
||||
ctrl.$setViewValue(ctrl.$viewValue);
|
||||
});
|
||||
var minValidator = function (value) {
|
||||
ctrl.$parsers.unshift( function(viewValue) {
|
||||
var min = (attr.ngMin) ? scope.$eval(attr.ngMin) : -Infinity;
|
||||
if (!Empty(value) && Number(value) < min) {
|
||||
if (!Empty(viewValue) && Number(viewValue) < min) {
|
||||
ctrl.$setValidity('ngMin', false);
|
||||
return undefined;
|
||||
} else {
|
||||
ctrl.$setValidity('ngMin', true);
|
||||
return value;
|
||||
return viewValue;
|
||||
}
|
||||
};
|
||||
ctrl.$parsers.push(minValidator);
|
||||
ctrl.$formatters.push(minValidator);
|
||||
});
|
||||
}
|
||||
};
|
||||
}])
|
||||
@@ -173,28 +167,21 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
||||
return {
|
||||
restrict: 'A',
|
||||
require: 'ngModel',
|
||||
// scope: true,
|
||||
link: function (scope, elem, attr, ctrl) {
|
||||
scope.$watch(attr.ngMax, function () {
|
||||
ctrl.$setViewValue(ctrl.$viewValue);
|
||||
});
|
||||
var maxValidator = function (value) {
|
||||
var max = scope.$eval(attr.ngMax) || Infinity;
|
||||
if (!Empty(value) && Number(value) > max) {
|
||||
ctrl.$parsers.unshift( function(viewValue) {
|
||||
var max = (attr.ngMax) ? scope.$eval(attr.ngMax) : Infinity;
|
||||
if (!Empty(viewValue) && Number(viewValue) > max) {
|
||||
ctrl.$setValidity('ngMax', false);
|
||||
return undefined;
|
||||
} else {
|
||||
ctrl.$setValidity('ngMax', true);
|
||||
return value;
|
||||
return viewValue;
|
||||
}
|
||||
};
|
||||
ctrl.$parsers.push(maxValidator);
|
||||
ctrl.$formatters.push(maxValidator);
|
||||
});
|
||||
}
|
||||
};
|
||||
}])
|
||||
|
||||
|
||||
.directive('smartFloat', function() {
|
||||
var FLOAT_REGEXP_1 = /^\$?\d+(.\d{3})*(\,\d*)?$/, //Numbers like: 1.123,56
|
||||
FLOAT_REGEXP_2 = /^\$?\d+(,\d{3})*(\.\d*)?$/; //Numbers like: 1,123.56
|
||||
|
||||
Reference in New Issue
Block a user