can-validate-legacy
Version:
Validation plugin for CanJS that provides an abstraction layer to your validation library of choice (Shim may be required).
44 lines (32 loc) • 1.19 kB
Markdown
{Object} validatejs-shim ValidateJS Shim
can-validate-legacy.shims
Hello world
This shim requires ValidateJS in the consuming app's package.json. It processes
the passed in options so they can be properly used by the ValidateJS libarary.
## Initialization
Import ValidateJS, validate plugin and this shim to immediately use the
ValidateJS in a CanJS project plugin.
```js
import "validatejs";
import "can-validate/can-validate";
import "can-validate/shims/validatejs.shim";
```
## Usage
`validate(MAP_OF_VALUES, MAP_OF_CONSTRAINTS)`
```javascript
var errors = validate.validate(user, constraints);
```
Validate is a can.Construct that is set to can.validate. It is possible to create
an instance for the purpose of storing errors in the instance. It is recommended
to use can.Map, can.Map.define, and can.Map.validate instead.
`once(VALUE, CONSTRAINTS, VALUE_NAME)`
```javascript
var errors = validate.once(user.firstName, constraints.firstName, 'firstName');
```
`isValid(VALUE, CONSTRAINTS, VALUE_NAME)`
```javascript
var errors = validate.once(user.firstName, constraints.firstName, 'firstName');
```