-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
172 lines (140 loc) · 6.02 KB
/
script.js
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
const loginInputEmail = document.getElementById('login-input-email');
const loginInputPass = document.getElementById('login-input-pass');
const loginButton = document.getElementById('login-button');
// Faz validação do login
loginButton.addEventListener('click', (event) => {
event.preventDefault();
if (loginInputEmail.value === 'tryber@teste.com' && loginInputPass.value === '123456') {
alert('Olá, Tryber!');
} else {
alert('Email ou senha inválidos.');
}
});
// Faz com que o botão só esteja habilitado caso o agreement-checkbox esteja marcado, e altera cor do botão
const submitBtn = document.querySelector('#submit-btn');
const agreementCheckbox = document.querySelector('#agreement');
agreementCheckbox.addEventListener('change', () => {
submitBtn.disabled = true;
submitBtn.style.backgroundColor = 'rgb(143, 143, 144';
if (agreementCheckbox.checked === true) {
submitBtn.disabled = false;
submitBtn.style.backgroundColor = 'rgb(80, 26, 124)';
}
});
// Faz contagem de caracteres restantes no campo textarea de observações
const textarea = document.querySelector('#textarea');
const counter = document.querySelector('#counter');
textarea.addEventListener('input', () => {
const num = textarea.value.length;
counter.innerText = 500 - num;
});
// Funções que pegam informações inputadas nos campos e exibe na tela após clicar no botão de enviar
const CreatePrincipalSection = document.createElement('section');
CreatePrincipalSection.setAttribute('id', 'principal-section');
const sectionNameAndLastname = document.querySelector('.form-input-name-container');
const firstContainer = document.querySelector('#first-container');
const inputName = document.querySelector('#input-name');
const inputLastName = document.querySelector('#input-lastname');
// Nome e Sobrenome
function replaceInputsNameWithText() {
const createParagraph = document.createElement('p');
createParagraph.innerText = `Nome: ${inputName.value} ${inputLastName.value}`;
firstContainer.removeChild(sectionNameAndLastname);
firstContainer.appendChild(createParagraph);
}
const sectionHouse = document.querySelector('.form-input-house-container');
const inputEmail = document.querySelector('#input-email');
const selectHouse = document.querySelector('#house');
// Email e Casa
function replaceInputsEmailAndSelectWithText() {
const createParagraph = document.createElement('p');
const createParagraphTwo = document.createElement('p');
createParagraph.innerText = `Email: ${inputEmail.value}`;
createParagraphTwo.innerText = `Casa: ${selectHouse.value}`;
firstContainer.removeChild(sectionHouse);
firstContainer.appendChild(createParagraph);
firstContainer.appendChild(createParagraphTwo);
}
// Família selecionada
const radioInputsFamily = document.getElementsByClassName('family');
const secondContainer = document.querySelector('#second-container');
const familyContainer = document.querySelector('#family-container');
function replaceInputsFamily() {
const createParagraph = document.createElement('p');
for (let i = 0; i < radioInputsFamily.length; i += 1) {
if (radioInputsFamily[i].checked === true) {
createParagraph.innerText = `Família: ${radioInputsFamily[i].value}`;
}
}
secondContainer.removeChild(familyContainer);
secondContainer.appendChild(createParagraph);
}
// Matéias que está com mais vontade de aprender
const contentCheckBoxInpusts = document.getElementsByClassName('subject');
const contentContainer = document.querySelector('#checkbox-content');
function supportReplaceInputsContent(text, value) {
let tempString = '';
if (text === 'Matérias: ') {
tempString += value;
} else {
tempString += `, ${value}`;
}
return tempString;
}
function replaceInputsContent() {
const createParagraph = document.createElement('p');
createParagraph.setAttribute('id', 'paragraph-content');
let text = 'Matérias: ';
for (let i = 0; i < contentCheckBoxInpusts.length; i += 1) {
if (contentCheckBoxInpusts[i].checked === true) {
text += supportReplaceInputsContent(text, contentCheckBoxInpusts[i].value);
}
createParagraph.innerText = text;
}
secondContainer.removeChild(contentContainer);
secondContainer.appendChild(createParagraph);
}
// Avaliação selecionada
const rateRadioInputs = document.getElementsByClassName('rate');
const evatualionContainer = document.querySelector('#evaluation-container');
function replaceRate() {
const createParagraph = document.createElement('p');
for (let i = 0; i < rateRadioInputs.length; i += 1) {
if (rateRadioInputs[i].checked === true) {
createParagraph.innerText = `Avaliação: ${rateRadioInputs[i].value}`;
}
}
evatualionContainer.removeChild(evatualionContainer.firstElementChild);
evatualionContainer.removeChild(evatualionContainer.firstElementChild);
evatualionContainer.appendChild(createParagraph);
}
// Campo de observações
const commentTextArea = document.querySelector('#textarea');
const textAreaContainer = document.querySelector('#textarea-container');
const formMain = document.querySelector('#evaluation-form');
const line = document.querySelector('#line');
const lineTwo = document.querySelector('#second-line');
function replaceTextArea() {
const createParagraph = document.createElement('p');
createParagraph.innerText = `Observações: ${commentTextArea.value}`;
textAreaContainer.removeChild(textAreaContainer.firstElementChild);
textAreaContainer.removeChild(textAreaContainer.firstElementChild);
textAreaContainer.removeChild(textAreaContainer.firstElementChild);
textAreaContainer.appendChild(createParagraph);
}
// Remove as linhas de decoração do Forms
function removeLines() {
formMain.removeChild(line);
formMain.removeChild(lineTwo);
}
// Função que chama todas as outras funções de substituição, quando o botão é clicado
submitBtn.addEventListener('click', (event) => {
event.preventDefault();
replaceInputsNameWithText();
replaceInputsEmailAndSelectWithText();
replaceInputsFamily();
replaceInputsContent();
replaceRate();
replaceTextArea();
removeLines();
});