-
Notifications
You must be signed in to change notification settings - Fork 58
PreValidate Form (on page load)
Stable since version 1.3.27+
By default Angular-Validation
does not display any error at first, at least not until user start typing test in each of the Form Elements. You can change this behavior and display the error right from the beginning by simply change a global option.
######Directive Change the Angular-Validation default options
myApp.controller('Ctrl', function ($scope) {
$scope.$validationOptions = {
debounce: 1500, // set the debounce globally
preValidateFormElements: true // pre-validate all form elements, false by default
};
});
######Service From the Service you can also change it by the following ways. P.S. This only works when all your input elements have been defined by the Angular-Validation Service
myApp.controller('Ctrl', function ($scope) {
// start by creating the service
var myValidation = new validationService();
// set property of preValidateFormElements (false by default)
myValidation.setGlobalOptions({ debounce: 1500, scope: $scope, preValidateFormElements: true });
});
####Note - How to reset a Form?
Angular-Validation is using the $touched
property for showing/hiding the errors, so if you want to reset your form then you should use the $setUntouched()
on your Form and you probably want to use the $setPristine()
as well. As shown in the Angular Guide, you can do the following
HTML
<input type="button" ng-click="reset(form)" value="Reset" />
Javascript (inside Controller)
$scope.reset = function(form) {
if (form) {
form.$setPristine();
form.$setUntouched();
}
$scope.user = angular.copy($scope.master);
};
Contents
- Angular-Validation Wiki
- Installation
- Demo
- Code Samples
- Functionalities
- Custom Validations
- Properties & Options
- Validators
- Tests
- Misc