mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 03:17:38 -02:30
added extra validation for integers, specifically for min/max, and for valid integer
added ng-min and ng-max directive, and made adjustments to question form for new directives
This commit is contained in:
@@ -38,10 +38,14 @@ angular.module('SurveyMakerFormDefinition', [])
|
|||||||
// '<input type="text" ng-model="survey_description" name="survey_description" id="survey_maker_survey_description" class="form-control ng-pristine ng-valid">'+
|
// '<input type="text" ng-model="survey_description" name="survey_description" id="survey_maker_survey_description" class="form-control ng-pristine ng-valid">'+
|
||||||
// '<div class="error api-error ng-binding" id="survey_maker-survey_description-api-error" ng-bind="survey_description_api_error"></div>'+
|
// '<div class="error api-error ng-binding" id="survey_maker-survey_description-api-error" ng-bind="survey_description_api_error"></div>'+
|
||||||
// '</div></div></div>'+
|
// '</div></div></div>'+
|
||||||
'<div class="col-sm-12"><label for="survey"><span class="label-text prepend-asterisk">Questions</span></label>'+
|
'<div class="col-sm-12">'+
|
||||||
'<div id="survey_maker_question_area"></div><div id="finalized_questions"></div>'+
|
'<label for="survey"><span class="label-text prepend-asterisk">Questions</span></label>'+
|
||||||
'<button style="display:none" type="button" class="btn btn-sm btn-primary" id="add_question_btn" ng-click="addNewQuestion()" aw-tool-tip="Create a new question" data-placement="top" data-original-title="" title="" disabled><i class="fa fa-plus fa-lg"></i> Add Question</button>'+
|
'<div id="survey_maker_question_area"></div>'+
|
||||||
'<div id="new_question"></div></div></div></div>'
|
'<div id="finalized_questions"></div>'+
|
||||||
|
'<button style="display:none" type="button" class="btn btn-sm btn-primary" id="add_question_btn" ng-click="addNewQuestion()" aw-tool-tip="Create a new question" data-placement="top" data-original-title="" title="" disabled><i class="fa fa-plus fa-lg"></i> Add Question</button>'+
|
||||||
|
'<div id="new_question"></div>'+
|
||||||
|
'</div>'+
|
||||||
|
'</div>'//</div>'
|
||||||
// label: 'Survey Name',
|
// label: 'Survey Name',
|
||||||
// type: 'text',
|
// type: 'text',
|
||||||
// addRequired: true,
|
// addRequired: true,
|
||||||
@@ -52,7 +56,7 @@ angular.module('SurveyMakerFormDefinition', [])
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
buttons: { //for now always generates <button> tags
|
// buttons: { //for now always generates <button> tags
|
||||||
// save: {
|
// save: {
|
||||||
// ngClick: 'formSave()', //$scope.function to call on click, optional
|
// ngClick: 'formSave()', //$scope.function to call on click, optional
|
||||||
// ngDisabled: true //Disable when $pristine or $invalid, optional
|
// ngDisabled: true //Disable when $pristine or $invalid, optional
|
||||||
@@ -61,6 +65,6 @@ angular.module('SurveyMakerFormDefinition', [])
|
|||||||
// ngClick: 'formReset()',
|
// ngClick: 'formReset()',
|
||||||
// ngDisabled: true //Disabled when $pristine
|
// ngDisabled: true //Disabled when $pristine
|
||||||
// }
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -89,6 +89,58 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
.directive('ngMin', ['Empty', function (Empty) {
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
require: 'ngModel',
|
||||||
|
link: function (scope, elem, attr, ctrl) {
|
||||||
|
scope.$watch(attr.ngMin, function () {
|
||||||
|
ctrl.$setViewValue(ctrl.$viewValue);
|
||||||
|
});
|
||||||
|
var minValidator = function (value) {
|
||||||
|
var min = scope.$eval(attr.ngMin) || -Infinity;
|
||||||
|
if (!Empty(value) && Number(value) < min) {
|
||||||
|
ctrl.$setValidity('ngMin', false);
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
ctrl.$setValidity('ngMin', true);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ctrl.$parsers.push(minValidator);
|
||||||
|
ctrl.$formatters.push(minValidator);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}])
|
||||||
|
|
||||||
|
.directive('ngMax', ['Empty', function (Empty) {
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
require: 'ngModel',
|
||||||
|
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.$setValidity('ngMax', false);
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
ctrl.$setValidity('ngMax', true);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ctrl.$parsers.push(maxValidator);
|
||||||
|
ctrl.$formatters.push(maxValidator);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}])
|
||||||
|
|
||||||
// integer Validate that input is of type integer. Taken from Angular developer
|
// integer Validate that input is of type integer. Taken from Angular developer
|
||||||
// guide, form examples. Add min and max directives, and this will check
|
// guide, form examples. Add min and max directives, and this will check
|
||||||
// entered values is within the range.
|
// entered values is within the range.
|
||||||
|
|||||||
Reference in New Issue
Block a user