forked from form-validation/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.html
executable file
·195 lines (191 loc) · 8.84 KB
/
basic.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en">
<head>
<title>L10n plugin - FormValidation</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" />
<link rel="stylesheet" href="/vendors/@form-validation/umd/styles/index.min.css" />
</head>
<body>
<div class="mb2 pa2">
Choose language
<button type="button" class="ba b--black-20 ph3 pv2 br2 setLocaleButton" data-locale="en_US">
English
</button>
<button type="button" class="ba b--black-20 ph3 pv2 br2 setLocaleButton" data-locale="vi_VN">
Tiếng Việt
</button>
</div>
<form id="demoForm" method="POST">
<div class="cf mb2">
<div class="fl w-100">
<div class="fl w-25 pa2">Username</div>
<div class="fl w-50">
<input type="text" name="username" class="input-reset ba b--black-20 pa2 mb2 db w-100" />
</div>
</div>
</div>
<div class="cf mb2">
<div class="fl w-100">
<div class="fl w-25 pa2">Email</div>
<div class="fl w-50">
<input type="text" name="email" class="input-reset ba b--black-20 pa2 mb2 db w-100" />
</div>
</div>
</div>
<div class="cf mb2">
<div class="fl w-100">
<div class="fl w-25 pa2">Password</div>
<div class="fl w-50">
<input type="password" name="password" class="input-reset ba b--black-20 pa2 mb2 db w-100" />
</div>
</div>
</div>
<div class="cf mb2">
<div class="fl w-100">
<div class="fl w-25 pa2">Gender</div>
<div class="fl w-50">
<label for="genderMale" class="lh-copy mr4"
><input class="mr2" type="radio" name="gender" id="genderMale" value="male" /> Male</label
>
<label for="genderFemale" class="lh-copy mr4"
><input class="mr2" type="radio" name="gender" id="genderFemale" value="female" />
Female</label
>
<label for="genderOther" class="lh-copy"
><input class="mr2" type="radio" name="gender" id="genderOther" value="other" />
Other</label
>
</div>
</div>
</div>
<div class="cf mb2">
<div class="fl w-100">
<div class="fl w-25 pa2">Date of birth</div>
<div class="fl w-50">
<input
type="text"
name="birthday"
placeholder="YYYY/MM/DD"
class="input-reset ba b--black-20 pa2 mb2 db w-100"
/>
</div>
</div>
</div>
<div class="cf mb2">
<div class="fl w-100">
<div class="fl w-25 pa2"></div>
<div class="fl w-50">
<button type="submit" class="ba b--black-20 bg-blue white ph3 pv2 br2">Submit</button>
</div>
</div>
</div>
</form>
<script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script>
<script src="/vendors/@form-validation/umd/plugin-tachyons/index.min.js"></script>
<script src="/vendors/@form-validation/umd/plugin-l10n/index.min.js"></script>
<script src="/vendors/@form-validation/umd/locales/en_US.min.js"></script>
<script src="/vendors/@form-validation/umd/locales/vi_VN.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function (e) {
const fv = FormValidation.formValidation(document.getElementById('demoForm'), {
// Set the default locale
locale: 'en_US',
localization: FormValidation.locales.en_US,
fields: {
// Since the messages of notEmpty, stringLength, regexp are not set here,
// they will be taken from language package
username: {
validators: {
notEmpty: {},
stringLength: {
min: 6,
max: 30,
},
regexp: {
regexp: /^[a-zA-Z0-9]+$/,
},
},
},
// Messages are taken from language package
email: {
validators: {
notEmpty: {},
emailAddress: {},
},
},
// Messages of notEmpty and stringLength validators
// are taken from language package
password: {
validators: {
notEmpty: {},
stringLength: {
min: 8,
},
different: {
compare: function () {
return form.querySelector('[name="username"]').value;
},
},
},
},
birthday: {
validators: {
notEmpty: {},
date: {
format: 'YYYY/MM/DD',
},
},
},
gender: {
validators: {
notEmpty: {},
},
},
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
tachyons: new FormValidation.plugins.Tachyons(),
submitButton: new FormValidation.plugins.SubmitButton(),
icon: new FormValidation.plugins.Icon({
valid: 'fa fa-check',
invalid: 'fa fa-times',
validating: 'fa fa-refresh',
}),
l10n: new FormValidation.plugins.L10n({
username: {
stringLength: {
// Method 2: Use a literal object to define messages
en_US: 'The username must be between %s and %s characters long',
vi_VN: 'Tên đăng nhập phải có ít nhất %s và nhiều nhất %s ký tự',
},
},
password: {
// Method 3: Use a callback to determine message in particular language
different: function (field, validator) {
return {
en_US: 'The password can not be same as username',
vi_VN: 'Mật khẩu phải khác tên đăng nhập',
};
},
},
}),
},
});
// Switch locale
const localeButtons = Array.from(document.querySelectorAll('.setLocaleButton'));
localeButtons.forEach(function (btn) {
btn.addEventListener('click', function () {
const locale = btn.getAttribute('data-locale');
fv.setLocale(locale, FormValidation.locales[locale]).resetForm();
});
});
});
</script>
</body>
</html>