-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathforms-validation-server.html
More file actions
140 lines (112 loc) · 4.72 KB
/
forms-validation-server.html
File metadata and controls
140 lines (112 loc) · 4.72 KB
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
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Bootstrap Hcode</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/style2.css">
</head>
<body>
<div class="container">
<form class="needs-validation" novalidate>
<div class="form-row">
<div class="col form-group">
<label for="first">Primeiro nome</label>
<input type="text" class="form-control is-valid" id="first" required>
<small class="text-muted">Digite sem abreviações.</small>
<div class="valid-feedback"> Muito bem!</div>
</div>
<div class="col form-group">
<label for="last">Último nome</label>
<input type="text" class="form-control is-invalid" id="last" required>
<small class="text-muted">Digite sem abreviações.</small>
<div class="valid-feedback">Muito bem!</div>
</div>
</div>
<div class="form-row">
<div class="col form-group">
<label for="email">E-mail</label>
<input type="email" class="form-control is-invalid" id="email" required>
<div class="invalid-feedback">Preencha um endereço de e-mail válido.</div>
</div>
<div class="col form-group">
<label for="phone">Telefone</label>
<input type="tel" class="form-control" id="phone" required>
</div>
</div>
<hr>
<div class="form-row">
<div class="col-sm-3 form-group">
<label for="zipcode">CEP</label>
<input type="text" class="form-control" id="zipcode">
</div>
</div>
<div class="form-row">
<div class="col-sm-9 form-group">
<label for="street">Endereço</label>
<input type="text" class="form-control" placeholder="Rua, Av..." id="street">
</div>
<div class="col-sm-3 form-group">
<label for="street-number">Número</label>
<input type="text" class="form-control" id="street-number">
</div>
</div>
<div class="form-row">
<div class="col-sm-6 form-group">
<label for="complement">Complemento</label>
<input type="text" class="form-control" id="complement">
</div>
<div class="col-sm-6 form-group">
<label for="district">Bairro</label>
<input type="text" class="form-control" id="district">
</div>
</div>
<div class="form-row">
<div class="col-sm-4 form-group">
<label for="city">Cidade</label>
<input type="text" class="form-control" id="city">
</div>
<div class="col-6 col-sm-4 form-group">
<label for="state">Estado</label>
<input type="text" class="form-control" id="state">
</div>
<div class="col-6 col-sm-4 form-group">
<label for="country">País</label>
<input type="text" class="form-control" id="country">
</div>
</div>
<div class="form-row">
<button class="btn btn-primary btn-block">Salvar</button>
</div>
</form>
</div>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script>
//Com jQuery
$(() => {
$('form').on('submit', event => {
const form = event.target;
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
$(form).addClass('was-validated');
});
});
//Sem jQuery
window.addEventListener("load", () => {
const form = document.querySelector('form');
form.addEventListener('submit', event => {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
});
});
</script>
</body>
</html>