Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

PreValidate Form (on page load)

Ghislain B edited this page Mar 23, 2017 · 16 revisions

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

// inject the ValidationService inside your Controller
myApp.controller('Ctrl', function ($scope, ValidationService) {
  // 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?

You can look at the Wiki - Reset Form

Clone this wiki locally