-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
119 lines (98 loc) · 5.09 KB
/
Copy pathscripts.js
File metadata and controls
119 lines (98 loc) · 5.09 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
// Simulação de envio do formulário
document.getElementById('cadastroForm').addEventListener('submit', function (e) {
e.preventDefault();
// Mostrar estado de loading no botão
const btnCadastrar = document.getElementById('btnCadastrar');
const originalText = btnCadastrar.textContent;
btnCadastrar.textContent = 'Processando...';
btnCadastrar.classList.add('loading');
// Simular requisição ao backend
setTimeout(() => {
// Remover estado de loading
btnCadastrar.textContent = originalText;
btnCadastrar.classList.remove('loading');
// Simular sucesso ou erro aleatoriamente (80% sucesso, 20% erro)
const success = Math.random() > 0.2;
showToast(success);
// Se foi sucesso, limpar formulário
if (success) {
document.getElementById('cadastroForm').reset();
}
}, 1500);
});
// Função para mostrar notificação toast
function showToast(success) {
const toast = document.getElementById('toastNotification');
const toastMessage = document.getElementById('toastMessage');
if (success) {
toastMessage.textContent = '✅ Cliente cadastrado com sucesso!';
toast.classList.remove('error');
} else {
toastMessage.textContent = '❌ Erro ao cadastrar cliente. Verifique os dados e tente novamente.';
toast.classList.add('error');
}
toast.classList.add('show');
// Esconder toast após 5 segundos
setTimeout(() => {
toast.classList.remove('show');
}, 5000);
}
// Máscara para CPF
document.getElementById('cpf').addEventListener('input', function (e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length > 3 && value.length <= 6) {
value = value.replace(/(\d{3})(\d{1,3})/, '$1.$2');
} else if (value.length > 6 && value.length <= 9) {
value = value.replace(/(\d{3})(\d{3})(\d{1,3})/, '$1.$2.$3');
} else if (value.length > 9) {
value = value.replace(/(\d{3})(\d{3})(\d{3})(\d{1,2})/, '$1.$2.$3-$4');
}
e.target.value = value;
});
// Máscara para telefone
document.getElementById('telefone').addEventListener('input', function (e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length === 0) return;
if (value.length <= 2) {
value = `(${value}`;
} else if (value.length <= 7) {
value = `(${value.substring(0, 2)}) ${value.substring(2)}`;
} else if (value.length <= 11) {
value = `(${value.substring(0, 2)}) ${value.substring(2, 7)}-${value.substring(7)}`;
} else {
value = `(${value.substring(0, 2)}) ${value.substring(2, 7)}-${value.substring(7, 11)}`;
}
e.target.value = value;
});
// Limpar formulário com confirmação
document.getElementById('btnLimpar').addEventListener('click', function (e) {
if (confirm('Tem certeza que deseja limpar todos os campos do formulário?')) {
document.getElementById('cadastroForm').reset();
// Mostrar toast de confirmação
const toast = document.getElementById('toastNotification');
const toastMessage = document.getElementById('toastMessage');
toastMessage.textContent = '✅ Formulário limpo com sucesso!';
toast.classList.remove('error');
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 3000);
} else {
e.preventDefault();
}
});
// Configurar data máxima para data de nascimento (18 anos atrás)
const dataNascimentoInput = document.getElementById('data_nascimento');
const hoje = new Date();
const dataMaxima = new Date(hoje.getFullYear() - 18, hoje.getMonth(), hoje.getDate());
dataNascimentoInput.max = dataMaxima.toISOString().split('T')[0];
// Configurar data mínima (120 anos atrás)
const dataMinima = new Date(hoje.getFullYear() - 120, hoje.getMonth(), hoje.getDate());
dataNascimentoInput.min = dataMinima.toISOString().split('T')[0];
// Restrição para o campo nome (apenas letras e espaços)
document.getElementById('nome').addEventListener('input', function (e) {
let value = e.target.value;
// Remove tudo que não for letra (incluindo acentos) ou espaço
value = value.replace(/[^a-zA-Z\u00C0-\u00FF\s]/g, '');
e.target.value = value;
});