mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 18:07:33 -02:30
Added awRange directive which watches min/max values for changes and updates validation accordingly.
This commit is contained in:
@@ -349,6 +349,41 @@ function(ConfigurationUtils, i18n, $rootScope) {
|
|||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
.directive('awRange', ['Empty', function(Empty) {
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
require: 'ngModel',
|
||||||
|
link: function(scope, elem, attr, ctrl) {
|
||||||
|
|
||||||
|
let checkRange = function(viewValue){
|
||||||
|
ctrl.$setValidity('awRangeMin', true);
|
||||||
|
ctrl.$setValidity('awRangeMax', true);
|
||||||
|
var max = (attr.rangeMax) ? scope.$eval(attr.rangeMax) : Infinity;
|
||||||
|
var min = (attr.rangeMin) ? scope.$eval(attr.rangeMin) : -Infinity;
|
||||||
|
if (!Empty(max) && !Empty(viewValue) && Number(viewValue) > max) {
|
||||||
|
ctrl.$setValidity('awRangeMax', false);
|
||||||
|
}
|
||||||
|
else if(!Empty(min) && !Empty(viewValue) && Number(viewValue) < min) {
|
||||||
|
ctrl.$setValidity('awRangeMin', false);
|
||||||
|
}
|
||||||
|
return viewValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.$watch(attr.rangeMin, function () {
|
||||||
|
checkRange(scope.$eval(attr.ngModel));
|
||||||
|
});
|
||||||
|
|
||||||
|
scope.$watch(attr.rangeMax, function () {
|
||||||
|
checkRange(scope.$eval(attr.ngModel));
|
||||||
|
});
|
||||||
|
|
||||||
|
ctrl.$parsers.unshift(function(viewValue) {
|
||||||
|
return checkRange(viewValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}])
|
||||||
|
|
||||||
.directive('smartFloat', function() {
|
.directive('smartFloat', function() {
|
||||||
var FLOAT_REGEXP = /^\-?\d+((\.|\,)\d+)?$/;
|
var FLOAT_REGEXP = /^\-?\d+((\.|\,)\d+)?$/;
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -232,9 +232,10 @@ export default
|
|||||||
type: 'custom',
|
type: 'custom',
|
||||||
control: '<div>'+
|
control: '<div>'+
|
||||||
'<label for="default_int"><span class="Form-inputLabel">Default Answer</span></label>'+
|
'<label for="default_int"><span class="Form-inputLabel">Default Answer</span></label>'+
|
||||||
'<input type="number" ng-model="default_int" name="default_int" aw-min="int_min" aw-max="int_max" class="form-control Form-textInput" integer />'+
|
'<input type="number" ng-model="default_int" name="default_int" aw-range range-min="int_min" range-max="int_max" class="form-control Form-textInput" integer />'+
|
||||||
'<div class="error" ng-show="survey_question_form.default_int.$error.number || survey_question_form.default_int.$error.integer">Please enter a valid integer.</div>'+
|
'<div class="error" ng-show="survey_question_form.default_int.$error.number || survey_question_form.default_int.$error.integer">Please enter a valid integer.</div>'+
|
||||||
'<div class="error" ng-show="survey_question_form.default_int.$error.awMin || survey_question_form.default_int.$error.awMax"> Please enter a value in the range of {{int_min}} to {{int_max}}.</div>'+
|
'<div class="error" ng-show="survey_question_form.default_int.$error.awRangeMin"> Please enter a minimum default of {{int_min}}.</div>'+
|
||||||
|
'<div class="error" ng-show="survey_question_form.default_int.$error.awRangeMax"> Please enter a maximum default of {{int_max}}.</div>'+
|
||||||
'</div>',
|
'</div>',
|
||||||
column: 2,
|
column: 2,
|
||||||
ngShow: 'type.type === "integer" ',
|
ngShow: 'type.type === "integer" ',
|
||||||
@@ -245,9 +246,10 @@ export default
|
|||||||
type: 'custom',
|
type: 'custom',
|
||||||
control: '<div>'+
|
control: '<div>'+
|
||||||
'<label for="default_float"><span class="Form-inputLabel">Default Answer</span></label>'+
|
'<label for="default_float"><span class="Form-inputLabel">Default Answer</span></label>'+
|
||||||
'<input type="number" ng-model="default_float" name="default_float" aw-min="float_min" aw-max="float_max" class="form-control Form-textInput" />'+
|
'<input type="number" ng-model="default_float" name="default_float" aw-range range-min="float_min" range-max="float_max" class="form-control Form-textInput" />'+
|
||||||
'<div class="error" ng-show="survey_question_form.default_float.$error.number || survey_question_form.default_float.$error.float">Please enter a valid float.</div>'+
|
'<div class="error" ng-show="survey_question_form.default_float.$error.number || survey_question_form.default_float.$error.float">Please enter a valid float.</div>'+
|
||||||
'<div class="error" ng-show="survey_question_form.default_float.$error.awMin || survey_question_form.default_float.$error.awMax"> Please enter a value in the range of {{float_min}} to {{float_max}}!</div>'+
|
'<div class="error" ng-show="survey_question_form.default_float.$error.awRangeMin"> Please enter a minimum default of {{float_min}}.</div>'+
|
||||||
|
'<div class="error" ng-show="survey_question_form.default_float.$error.awRangeMax"> Please enter a maximum default of {{float_max}}.</div>'+
|
||||||
'</div>',
|
'</div>',
|
||||||
column: 2,
|
column: 2,
|
||||||
ngShow: 'type.type=== "float" ',
|
ngShow: 'type.type=== "float" ',
|
||||||
|
|||||||
Reference in New Issue
Block a user