-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
64 lines (54 loc) · 1.21 KB
/
example.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//inheriting Person from ValidationModel
var Person = function (name,age) {
ValidationModel.apply(this,arguments);
this.name = name;
this.age = age;
this.email = null;
};
Person.prototype = Object.create(ValidationModel.prototype);
Person.prototype.validations={
name:{
rules:['required'],
controlName:"Name"
},
age:{
rules:['number'],
controlName:"Age"
}
}
//inheriting adult from Person
var Adult = function (name, age, email) {
Person.apply(this,arguments);
this.email = email;
}
Adult.prototype = Object.create(Person.prototype);
Adult.prototype.customValidators = {
customEmail:function (obj, email) {
if(!email || email.length<6)
return{
code:1111,
msg:"email should be longer than 6 char"
}
}
}
Adult.prototype.validations={
email:{
rules:['required','customEmail'],
controlName:"Email"
}
}
//inheriting unknown person from Person
var UnknownPerson = function (name, age, country) {
Person.apply(this,arguments);
this.foundIn = country;
}
UnknownPerson.prototype = Object.create(Person.prototype);
UnknownPerson.prototype.validations={
email:null,
name:null,
foundIn:{
rules : ["required"],
messages : ["Please provide @controlName"],
controlName : "Found in country"
}
}