-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
validation.js
41 lines (39 loc) · 1.41 KB
/
validation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {ObserverLocator} from 'aurelia-binding';
import {ValidationGroup} from './validation-group';
import {inject} from 'aurelia-dependency-injection';
import {ValidationConfig} from './validation-config';
/**
* A lightweight validation plugin
* @class Validation
* @constructor
*/
@inject(ObserverLocator)
export class Validation {
/**
* Instantiates a new {Validation}
* @param observerLocator the observerLocator used to observer properties
* @param validationConfig the configuration
*/
constructor(observerLocator, validationConfig) {
this.observerLocator = observerLocator;
this.config = validationConfig ? validationConfig : Validation.defaults;
}
/**
* Returns a new validation group on the subject
* @param subject The subject to validate
* @returns {ValidationGroup} A ValidationGroup that encapsulates the validation rules and current validation state for this subject
*/
on(subject, configCallback) {
let conf = new ValidationConfig(this.config);
if (configCallback !== null && configCallback !== undefined && typeof(configCallback) === 'function') {
configCallback(conf);
}
return new ValidationGroup(subject, this.observerLocator, conf);
}
onBreezeEntity(breezeEntity, configCallback) {
let validation = this.on(breezeEntity, configCallback);
validation.onBreezeEntity();
return validation;
}
}
Validation.defaults = new ValidationConfig();