-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
161 lines (135 loc) · 3.9 KB
/
index.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta http-equiv="x-ua-compatible" content="IE=Edge">
<link href="css/style.css" rel="stylesheet">
<link href="js/tooltipster/tooltipster.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="paper">
<section class="boxed">
<div class="inner">
<section class="section-header left">
<h3 class="title">完整 <span class="title-highlight">example</span></h3>
</section>
<form action="#" class="column-wrap" id="realExample">
<section class="one-third">
<input type="text" id="username" data-valid="required noChinese" placeholder="Username">
</section>
<section class="one-third">
<input type="text" data-valid="required ajaxUsernameExist2 ajaxUsernameExist" placeholder="异步验证示例">
</section>
<section class="one-third">
<input type="text" data-valid="required abc" placeholder="abc (自定义验证规则示例)">
</section>
<section class="one-third">
<input type="password" data-valid="required" name="password" placeholder="Password">
</section>
<section class="one-third">
<input type="password" data-valid="required equal_password" name="password2" placeholder="Password 一致 (验证规则传参示例)">
</section>
<section class="one-third last">
<input type="text" id="email" data-valid="required email" placeholder="Email" name="email">
<p class="help-regex">regex error</p>
</section>
<section>
<textarea data-valid="required minLength" data-min-length="10"></textarea>
<p class="help-minLength">minLenght error</p>
</section>
<section>
<input type="checkbox" data-valid="required" />
</section>
<section>
<input type="submit" class="pureBtn big red">
</section>
</form>
<form action="#" id="submitValid">
<section class="one-third">
<input type="text" data-valid="required email" placeholder="Email:"><br>
</section>
<section class="one-third">
<input type="password" data-valid="required minLength_10 maxLength_15" placeholder="Password:">
</section>
<section class="one-third">
<input type="submit" class="pureBtn big red">
</section>
</form>
</div>
</section>
</div> <!-- end paper -->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/tooltipster/jquery.tooltipster.js"></script>
<script src="js/formValidHelper.js"></script>
<script>
formValid.submitValid($('#submitValid'));
formValid.blurValid($('#realExample'));
form.isAbc = function($el){
return {
isPassed: $el.val().toLowerCase() == 'abc',
$el: $el,
type: 'abc',
msg: '此处不是 abc'
};
}
form.isAjax = function($el){
tooltips.error($el, 'validting');
var defered = $.Deferred();
setTimeout(function() {
defered.resolve({
$el: $el,
isPassed: true,
type: 'ajax'
});
}, 3000);
return {
isPassed: false,
$el: $el,
isDeferred: true,
deferred: defered.promise(),
func: function(abc){
tooltips.error($el, abc);
}
};
}
form.isAjaxUsernameExist = function($el){
var This = this;
setTimeout(function(){
This.resolve({
$el: $el,
isPassed: false,
type: 'ajaxUsernameExist',
msg: '用户名可用'
});
}, 2000);
return This.promise();
};
form.isAjaxUsernameExist2 = function($el){
var This = this;
setTimeout(function(){
This.resolve({
$el: $el,
isPassed: false,
type: 'ajaxUsernameExist2',
msg: '用户名不可用'
});
}, 2000);
return This.promise();
};
// form.msg.abc = '* abc';
$('#realExample').on('submit', function(e){
e.preventDefault();
formValid.tests($(this).find('[data-valid]')).then(function(result){
if(!result.isPassed) {
return;
}
// $('#realExample').off('submit').trigger('submit');
});
});
</script>
</body>
</html>