forked from form-validation/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap3.html
149 lines (142 loc) · 6.45 KB
/
bootstrap3.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>MandatoryIcon plugin - FormValidation</title>
<meta charset="utf-8" />
<meta content="width=device-width,initial-scale=1" name="viewport" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="/vendors/@form-validation/umd/styles/index.min.css" />
</head>
<body>
<form id="productForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-3 control-label">Name</label>
<div class="col-xs-5">
<input type="text" class="form-control" name="name" />
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label">Description</label>
<div class="col-xs-5">
<textarea class="form-control" name="description" rows="5"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label">Price</label>
<div class="col-xs-3">
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="text" class="form-control" name="price" />
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label">Size</label>
<div class="col-xs-3">
<div class="checkbox">
<label><input type="checkbox" name="size" value="s" /> S</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="size" value="m" /> M</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="size" value="l" /> L</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="size" value="xl" /> XL</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label">Quantity</label>
<div class="col-xs-3">
<input type="text" class="form-control" name="quantity" />
</div>
</div>
<div class="form-group">
<div class="col-xs-9 col-xs-offset-3">
<button type="submit" class="btn btn-default" id="addBtn">Add product</button>
<button type="button" class="btn btn-info" id="resetBtn">Reset form</button>
</div>
</div>
</form>
<script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script>
<script src="/vendors/@form-validation/umd/plugin-bootstrap3/index.min.js"></script>
<script src="/vendors/@form-validation/umd/plugin-mandatory-icon/index.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function (e) {
const fv = FormValidation.formValidation(document.getElementById('productForm'), {
fields: {
name: {
validators: {
notEmpty: {
message: 'The name is required',
},
},
},
description: {
validators: {
stringLength: {
max: 300,
message: 'The description must be less than 300 characters long',
},
notEmpty: {
message: 'The description is required',
},
},
},
price: {
validators: {
notEmpty: {
message: 'The price is required',
},
numeric: {
message: 'The price must be a number',
},
},
},
size: {
validators: {
notEmpty: {
message: 'The size is required',
},
},
},
quantity: {
validators: {
notEmpty: {
message: 'The quantity is required',
},
integer: {
message: 'The quantity must be a number',
},
},
},
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
submitButton: new FormValidation.plugins.SubmitButton(),
bootstrap3: new FormValidation.plugins.Bootstrap3(),
// We must register `MandatoryIcon` before `Icon` plugin
mandatoryIcon: new FormValidation.plugins.MandatoryIcon({
icon: 'glyphicon glyphicon-asterisk',
}),
icon: new FormValidation.plugins.Icon({
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh',
}),
},
});
document.getElementById('resetBtn').addEventListener('click', function () {
fv.resetForm(true);
});
});
</script>
</body>
</html>