forked from sofish/validator.js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
executable file
·145 lines (116 loc) · 4.34 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1,requiresActiveX=true"/>
<title>validate.js</title>
<style type="text/css">
body{padding: 30px;font-family:lucida grande;}
label{display:block;width:180px}
.error{border:2px solid #f36!important;}
.editable{min-height:100px;_zoom:1;_height:100px;border:1px solid gray;}
</style>
</head>
<body class="typo">
<h3># Example Product</h3>
<ul>
<li>Simple: <a href="http://inews.io/account/register">http://inews.io/account/register</a></li>
<li>Advance: <a href="http://shanghai.baixing.com/fabu/ershouqiche">http://shanghai.baixing.com/fabu/ershouqiche</a></li>
</ul>
<h3># form validator</h3>
<form action="/" id="form">
<p>
<select name="select" id="" required data-error="select">
<option value="1">item 1</option>
<option value="2">item 2</option>
<option value="3">item 3</option>
</select>
</p>
<p><label>Text: <input name="text" required maxlength="1" list="list"></label>
<datalist id="list">
<select name="text">
<option>A
<option>B
<option>C
<option>D
</select>
</datalist>
<p><label>Number: <input type="number" required></label>
<p><label>Number
<small>(1 < value < 10)</small>:
<input type="number" required min="1" max="10"></label>
<p><label>Negative number
<small>(-10 < value < 10)</small>:
<input type="number" required min="-10" max="10"></label>
<p><label>Number with step
<small>(1 < value < 10, step === 2)</small>:
<input type="number" required min="1" max="10" step="2"></label>
<p><label>Range
<small>(1 to 5)</small>:
<input type="range" required min="1" max="5"></label>
<p><label>Email: <input type="email" required></label>
<p><label>Url: <input type="url" required></label>
<p><label>Tel: <input type="tel" required></label>
<p><label>Mobile: <input type="mobile" required></label>
<p><label>Password: <input type="password" required></label>
<p><label>Async Validate:
<input type="text" data-url="https://api.github.com/legacy/user/search/china" data-method="getJSON" required></label></p>
<p><label>A or B:</label>
<input type="text" data-aorb="a" required>
<br />
<input type="text" data-aorb="b" required>
</p>
<p>
<label><input type="radio" required name="abc" value="A">[A]</label>
<label><input type="radio" required name="abc" value="B">[B]</label>
<label><input type="radio" required name="abc" value="C">[C]</label>
<p><label>Custom Event: <input id="event" type="text" data-event="hello" required></label>
<p><textarea maxlength="20" placeholder="some text" required data-error="textarea"></textarea></p>
<p>Input email here:
<div>
<div class="editable" contenteditable required type="email">[email protected]</div>
</div>
<p>Input a number here:
<div>
<div class="editable" contenteditable required pattern="^\d+$">123</div>
</div>
<div class="new-input-area"></div>
<p>
<button id='js-add-input' type="button">add new input </button>
</p>
<p>
<input type="submit" value="send"/>
</p>
</form>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="validator.js"></script>
<script type="text/javascript">
$.validatorSetup({
errorCallback: function(fields){
// may not support form in modal
if (fields.length) {
var top = fields[0].$el.offset().top - 100
$('html, body').animate({ scrollTop: top })
}
}
})
$('#form').validator({
isErrorOnParent: true
});
var nameIndex = 1;
$('#js-add-input').on("click", function(){
$('.new-input-area').append($('<p>6-20 charsets [input-' + nameIndex + ']: <input type="text" name="new-' + ++nameIndex + '" required pattern="^.{6,20}$"></p>'))
})
$('#form').on('submit', function(event){
event.preventDefault();
alert("submitted!");
})
$('#event').on('before:hello', function(event, element){
//console.log('`before.hello` event trigger on $("#' + element.id + '")');
})
$('#event').on('after:hello', function(event, element){
//console.log('`after.hello` event trigger on $("#' + element.id + '")');
})
</script>
</body>
</html>