forked from form-validation/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
show-icons-custom-area.html
100 lines (93 loc) · 4.35 KB
/
show-icons-custom-area.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>FormValidation example - Showing icons in custom area</title>
<meta charset="utf-8" />
<meta content="width=device-width,initial-scale=1" name="viewport" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
/>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/css/tachyons.min.css" />
<!-- Replace with your path -->
<link rel="stylesheet" href="/vendors/@form-validation/umd/styles/index.min.css" />
<style>
.fv-plugins-icon[data-field='username'],
.fv-plugins-icon[data-field='email'] {
display: inline-block;
position: static;
height: auto;
line-height: normal;
}
</style>
</head>
<body>
<form id="demoForm" method="POST" class="fv-stacked-form">
<div class="row mb2">
<label class="db pv2">Username</label>
<input type="text" class="input-reset ba b--black-20 pa2 mb2 db w-50" name="username" />
</div>
<div class="row mb2">
<label class="db pv2">Email address</label>
<input type="text" class="input-reset ba b--black-20 pa2 mb2 db w-50" name="email" />
</div>
<div class="row mb2">
<button type="submit" class="ba b--black-20 bg-blue white ph3 pv2 br2">Submit</button>
</div>
</form>
<!-- Replace with your path -->
<script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script>
<script src="/vendors/@form-validation/umd/plugin-tachyons/index.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function (e) {
FormValidation.formValidation(document.getElementById('demoForm'), {
fields: {
username: {
validators: {
notEmpty: {
message: 'The username is required and cannot be empty',
},
stringLength: {
min: 6,
max: 30,
message: 'The username must be more than 6 and less than 30 characters long',
},
regexp: {
regexp: /^[a-zA-Z0-9_]+$/,
message: 'The username can only consist of alphabetical, number and underscore',
},
},
},
email: {
validators: {
notEmpty: {
message: 'The email is required and cannot be empty',
},
emailAddress: {
message: 'The input is not a valid email address',
},
},
},
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
tachyons: new FormValidation.plugins.Tachyons(),
submitButton: new FormValidation.plugins.SubmitButton(),
icon: new FormValidation.plugins.Icon({
valid: 'material-icons valid-icon',
invalid: 'material-icons invalid-icon',
validating: 'material-icons validating-icon',
onPlaced: function (e) {
if (e.field === 'username' || e.field === 'email') {
const parent = e.iconElement.parentNode;
const label = parent.querySelector('label');
label.appendChild(e.iconElement);
}
},
}),
},
});
});
</script>
</body>
</html>