-
Notifications
You must be signed in to change notification settings - Fork 240
/
demo3.js
99 lines (96 loc) · 2.86 KB
/
demo3.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
define(function (require, exports, module) {
//引入依赖的组件
var $ = require('jquery'),
bootstrap = require('bootstrap'),
Form = require('mod/form'),
Validation = require('mod/formValidation'),
Url = require('mod/url');
//定义常量及组件初始化
var API = {
save: 'api/user/save'
},
BUTTONS = {
SAVE: $('#btn-save')
},
appForm = window.f = new Form('#appForm', {
mode: Url.getParam('mode'),
fieldOptions: {
name: {
onBeforeChange: function(e, val) {
if(val == "1"){
e.preventDefault();
}
}
}
}
}),
validation = window.v = new Validation(appForm.$element, {
rules: {
name: {
required: true
},
birthday: {
required: true
},
hobby: {
required: true
},
gender: {
required: true
},
work: {
required: true
},
industry: {
required: true
},
desc: {
required: true,
minlength: 10,
maxlength: 20
},
detailDesc: {
required: true
}
},
messages: {
name: {
required: '请输入姓名'
},
birthday: {
required: '请选择生日'
},
hobby: {
required: '请勾选兴趣爱好'
},
gender: {
required: '请勾选性别'
},
work: {
required: '请选择职业'
},
industry: {
required: '请选择行业'
},
desc: {
required: '请输入简介',
minLength: Validation.validator.format("请至少输入{0}个字符!"),
maxLength: Validation.validator.format("您输入不能超过{0}个字符!")
},
detailDesc: {
required: '请输入详细描述',
}
},
fieldTypeConfig: {
all: {
fvTipTarget: function ($field) {
return $field.parent();
}
}
}
});
//业务逻辑
BUTTONS.SAVE.click(function () {
validation.form();
});
});