Over a million developers have joined DZone.

vadacl: A Library For Streamlining Form Validation in Angular 2

DZone's Guide to

vadacl: A Library For Streamlining Form Validation in Angular 2

Need a library for streaming form validation in Angular 2? vadacl provides the a number of enhancements to the typical implementation of form validation.

· Web Dev Zone ·
Free Resource

Learn how Crafter’s Git-based content management system is reinventing modern digital experiences.

The initial version of my TypeScript-based vadacl library for performing form validation in Angular 2 is now available on GitHub.

vadacl provides the following enhancements to the typical implementation of form validation via the reactive form classes (FormControl, FormGroup, FormArray, and FormBuilder):

  • Instead of configuring all of the validation in the component hosting the form, you can configure certain validations within the data object itself (validation rules that should remain consistent wherever the data object is used in your application), then add to or modify those validation rules in the component to create the final set of validations needed for a given form.
  • The vadacl validation methods add a "message" property to the metadata object returned when the form data fails validation.  This "message" property value is the message meant to be presented to the user, and can be configured and/or overridden at multiple levels:
    • The method level, via a set of default message values
    • The data object
    • The component level
  • The Vadacl class, whether used as a superclass for your component or as a service, provides methods for providing an array of validator methods to the FormControls in your form and for displaying the validation error "message" values in your template, removing the need to add multiple DOM elements with "ngIf" directives to display each kind of validation error or to add code to your component to gather and translate validation failures into error messages.

vadacl is (currently) a small library contained in a single folder you can just drop into your Angular application. The GitHub repo contains that folder as part of a small Angular 2.1.1 application containing several working demos of vadacl in action.


Crafter CMS is a modern Git-based platform for building innovative websites and content-rich digital experiences. Download this white paper now.

reactive ,dom ,web dev

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}