diff --git a/2-formulario-com-validacao/index.html b/2-formulario-com-validacao/index.html new file mode 100644 index 0000000..cda4d07 --- /dev/null +++ b/2-formulario-com-validacao/index.html @@ -0,0 +1,33 @@ + + + + + + + + + + + Quest HTML + CSS + JS intermediário - Desafio - Formulário com validação + + +
+
+

FICOU COM DÚVIDA?
NOS MANDE UMA MENSAGEM!

+

caso tenha ficado com qualquer dúvida basta nos mandar uma mensagem e entraremos em contato em menos de 24h.

+
+
+ + + + + + + + + *campos obrigatórios + +
+
+ + \ No newline at end of file diff --git a/2-formulario-com-validacao/src/css/style.css b/2-formulario-com-validacao/src/css/style.css new file mode 100644 index 0000000..4ec7e2c --- /dev/null +++ b/2-formulario-com-validacao/src/css/style.css @@ -0,0 +1,125 @@ +* { + box-sizing: border-box; +} + +html, body { + font-family: 'Roboto', sans-serif; + font-size: 15px; + margin: 0; + padding: 0; +} + +body { + min-height: 100vh; + display: flex; + justify-content: center; + align-items: center; + background-image: radial-gradient(rgba(223,101,150,0.65), rgba(98,130,229,0.85)); +} + +.container { + width: 800px; + min-height: 402px; + display: flex; + align-items: center; + justify-content: space-around; + outline: 1px outset black; + background-image: linear-gradient(rgb(223,101,150), rgb(98,130,229)); +} + +.container .mensagem { + width: 37.5%; + color: white; +} + +.container .mensagem h2 { + font-size: 20px; + font-weight: 900; +} + +.container .formulario { + width: 340px; + background-color: white; + padding: 20px; +} + +.container .formulario > * { + display: block; + width: 100%; +} + +.container .formulario input, +.container .formulario textarea { + border: 1px solid #000; + border-radius: 5px; + padding: 9px; +} + +.container .formulario input:not(:first-child), +.container .formulario textarea, +.container .formulario .alerta { + margin-top: 15px; +} + +.container .formulario .alerta { + margin-left: -5px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.container .formulario .error { + border-color: red; +} + +.container .formulario .ok { + border-color: #00C22B; +} + +.container .formulario .error + span:empty:after { + content: 'campo obrigatório'; + color: #F52E2E; + font-size: 8px; + position: absolute; +} + +.container .formulario textarea { + height: 100px; + resize: none; + scrollbar-width: thin; +} + +.container .formulario input[type=submit] { + color:white; + background-color: #3CCC87; + border-color: transparent; + font-weight: 700; +} + +@media (max-width: 800px) { + .container { + outline-width: 2px; + } +} + +@media (max-width: 600px) { + .container { + flex-direction: column; + padding-bottom: 1em; + } + .container .mensagem p { + text-align: justify; + } + .container > * { + min-width: 80%; + } + .container, + .container .container .mensagem { + max-width: 100%; + } + .container .formulario { + max-width: 95%; + background-color: rgba(255,255,255,0.5); + border-radius: 5px; + } +} \ No newline at end of file diff --git a/2-formulario-com-validacao/src/js/script.js b/2-formulario-com-validacao/src/js/script.js new file mode 100644 index 0000000..127c738 --- /dev/null +++ b/2-formulario-com-validacao/src/js/script.js @@ -0,0 +1,25 @@ +function validateInput(input, adderror = false){ + if (input.checkValidity()){ + input.classList.remove("error"); + input.classList.add("ok"); + } else { + if (adderror) input.classList.add("error"); + input.classList.remove("ok"); + } +} + +function validateForm() { + inputs.forEach((input) => { + validateInput(input, true); + }); +} + +const inputs = document.querySelectorAll(".formulario input:not([type=submit]), .formulario textarea"); + +document.querySelector(".formulario input[type=submit]").addEventListener('click', validateForm); + +inputs.forEach(input => { + input.addEventListener('input', function(){ + validateInput(input); + }); +}); \ No newline at end of file