ng-schema

Client side validation in AngularJS with Mongoose Schemas
Homepage:
0 people use it
Author: 240801?v=3 dalcib

ng-schema

ng-schema allows to use Mongoose Schemas in Angular forms.

It isn't a form generator. You build your form normaly and associate to a schema, and all valitations will be ready to use.

Motivation

The program uses a declarative way to express the user interface and application behavior. Thus, the business rules are defined in the View in HTML form. Is not good because these rules are mixed with the presentation layer.

D.R.Y.

Using Mongoose Schemas to define the Business Rules, it is not needed to repeat the validations rules in each form. All rules are in one place, in an Angular service.

Overview

It is the same as:

Documentation

Types

  • String, Number, Boolean, Date or
  • 'text', 'string', 'number', 'integer', 'date','month', 'time', 'week', 'checkbox', 'radio', 'email', 'url', 'search', 'password'

Constraints

  • min, max, maxlength, minlength, required, match (or pattern)

Helpers

  • enum, default

Html Attributes

The schema can be used to define elements atributes like: name, title, disable, readonly, step, placeholder

Assessors and Modifiers

  • get, set, validate, virtual (default in Mongoose)
  • formatter, parser (for use in Angular forms)

Notes

  • If a attribute is defined in the form, it won't be overwritten for the schema value. So, the rules can be customised in a specific form, if it is needed.
  • Both HTML5 constraints and Angular constraints are defined. If there is the maxlength in the schema, the attributes ng-maxlegth and maxlength are defined. If necessary, use the attribute novalidate in the form to stop HTML5 validation.
  • The Mongoose schema is extended to accept string Types, formatters, parsers and pattern.
  • The attributes label, description and format can be used to help in another directives.

TODO

  • More tests
  • enum
  • ref - populate
  • JSON-Schemas
comments powered by Disqus
This page was last updated almost 3 years ago.