-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.html
121 lines (110 loc) · 4.79 KB
/
template.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<title>Formulário</title>
</head>
<body>
<div class="container mt-3">
<div class="row">
<div class="col-2"></div>
<div class="col-8">
<form action>
<div class="mb-3">
<label for="nome" class="form-label">Informe o
nome:</label>
<input type="text" class="form-control" name="nome" id="nome">
</div>
<div class="mb-3">
<label for="cpf" class="form-label">Informe o
CPF:</label>
<input type="text" class="form-control" name="cpf" id="cpf">
</div>
<div class="mb-3">
<label for="email" class="form-label">Informe o
Email:</label>
<input type="text" class="form-control" name="email" id="email">
</div>
<div>
<input type="button" class="btn btn-primary" value="Salvar" onclick="validar_form()">
<input type="button" class="btn btn-info" value="Limpar tabelas" onclick="limpar_tabela()">
</div>
</form>
<div class="toast hide" id="toast-msg">
<div class="toast-header">
<strong class="me-auto" id="titulo-msg">Toast
Header</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast"></button>
</div>
<div class="toast-body">
<p id="conteudo-msg">Some text inside the toast body
</p>
</div>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>Nome</th>
<th>CPF</th>
<th>Email</th>
</tr>
</thead>
<tbody id="corpo-tabela">
<tr>
<td>melo</td>
<td>1111</td>
<td>email melo</td>
</tr>
</tbody>
</table>
</div>
<div class="col-2"></div>
</div>
</div>
<script>
function limpar_tabela() {
let pai = document.getElementById('corpo-tabela');
while (pai.firstChild) {
pai.removeChild(pai.firstChild);
}
}
function mostrar_mensagem(titulo, conteudo) {
document.getElementById('titulo-msg').innerHTML = titulo;
document.getElementById('conteudo-msg').innerText = conteudo;
document.getElementById('toast-msg').setAttribute('class', 'toast show');
}
function validar_form() {
let nome = document.getElementById("nome").value;
if (nome.trim() == "") {
mostrar_mensagem('Atenção', 'Informe o nome');
document.getElementById("nome").focus();
return;
}
if (nome.trim().length < 4) {
mostrar_mensagem('Atenção', 'O nome deverá ter no mínimo 4 caracteres');
return;
}
if (nome.trim().length > 10) {
mostrar_mensagem('Atenção', 'O nome deverá ter no máximo 10 caracteres');
return;
}
//mostrar_mensagem('Aviso', 'Os dados do formulário estão válidos');
let linha_tabela = document.createElement('tr');
let coluna_nome = document.createElement('td');
coluna_nome.textContent = document.getElementById('nome').value;
let coluna_cpf = document.createElement('td');
coluna_cpf.textContent = document.getElementById('cpf').value;
let coluna_email = document.createElement('td');
coluna_email.textContent = document.getElementById('email').value;
//adicionando as colunas a linha
linha_tabela.append(coluna_nome);
linha_tabela.append(coluna_cpf);
linha_tabela.append(coluna_email);
document.getElementById('corpo-tabela').append(linha_tabela);
}
</script>
</body>
</html>