This repository has been archived by the owner on Jul 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Global Options
Ghislain B. edited this page Jul 21, 2015
·
38 revisions
To change default options globally, you can use the $scope.$validationOptions
. These global options can be defined for both the Directive and/or the Service.
For more details about the ControllerAs
option, please refer to the Wiki - ControllerAs Syntax
######Directive/Service
myApp.controller('Ctrl', function ($scope, validationService) {
$scope.$validationOptions = {
// use the ControllerAs syntax
controllerAs: vm,
// set the debounce globally
debounce: 1500,
// display only last error message on each input element (false by default)
// for example if 3 errors are on the element, only the last message would show up
displayOnlyLastErrorMsg: false,
// set which scope Angular-Validation will use
// mainly used by $validationSummary and by checkFormValidity(), resetForm(), removeValidator()
isolatedScope: $scope,
// pre-validate all form elements, false by default
preValidateFormElements: false
};
});
All of these options can also be defined using the Service.
######Service Only
myApp.controller('Ctrl', function ($scope, validationService) {
// start by creating the service
var myValidation = new validationService();
// define the scope and isolatedScope, the scope property always needs to be there
myValidation.setGlobalOptions({
// use the ControllerAs syntax
controllerAs: vm,
// set the debounce globally
debounce: 1500,
// display only last error message on each input element (false by default)
// for example if 3 errors are on the element, only the last message would show up
displayOnlyLastErrorMsg: false,
// set which scope Angular-Validation will use, mainly for $validationSummary and checkFormValidity()
// scope & isolatedScope are equivalent but scope is mandatory while isolatedScope is not, so it is suggested to just use scope:
scope: $scope,
isolatedScope: $scope,
// pre-validate all form elements, false by default
preValidateFormElements: false
});
});
Contents
- Angular-Validation Wiki
- Installation
- Demo
- Code Samples
- Functionalities
- Custom Validations
- Properties & Options
- Validators
- Tests
- Misc