Validatious 2.0

Easy form validation with unobtrusive JavaScript

Introduction

The DSL API is a small but powerful API that lies on top of the core API. It's just a facade, and brings no new functionality to the table, except making validation a lot easier, more compact and easier to read. This is especially true when you have alot of compound rules.

For the most part, operations through the DSL API returns facade objects that wrap core objects such as v2.Field and v2.CompositeFormItem. As such, you have access to the full flexibility of Validatious, even if there's not always a special DSL method to do what you want. Configuration is one example that is not handled through any special method.

Exposing the DSL

In order to look like a real DSL, the extension needs to introduce a set of "words" (functions) in the global namespace. Validatious tries to minimize its impact on the global namespace with all functionality implemented in the v2 namespace, and a few extensions to native objects. For this reason, the following methods are initially namespaced:

By simply calling v2.dsl.expose();, all these methods are introduced in the global scope, allowing you to call them directly:

v2.dsl.expose();
validate(/* ... */);

If having these in the global namespace is a problem, just call them by their full names:

v2.dsl.validate(/* ... */);

In the remaining features, we will assume that the v2.dsl.expose method has been called.

Next: Enable validation on a form | Back to DSL features index

© 2008 Christian Johansen. Validatious is licensed with a BSD License, documentation and site content with CC Attribution-Share Alike. About.