Skip to content

Commit 2cf863a

Browse files
committed
update login & register html, styles.css, index.js
add Bootstrap custom client-side validation for the login and register forms
1 parent 5a8a528 commit 2cf863a

File tree

4 files changed

+143
-13
lines changed

4 files changed

+143
-13
lines changed

static/index.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,48 @@ window.dataLayer = window.dataLayer || [];
33
function gtag(){dataLayer.push(arguments);}
44
gtag('js', new Date());
55

6-
gtag('config', 'G-36KQSD0BWH');
6+
gtag('config', 'G-36KQSD0BWH');
7+
8+
// Example starter JavaScript for disabling form submissions if there are invalid fields
9+
(function () {
10+
'use strict'
11+
12+
window.addEventListener('load', function() {
13+
// Fetch all the forms we want to apply custom validation styles
14+
var inputs = document.getElementsByClassName('form-control')
15+
16+
// Loop over each input and watch blue event
17+
var validation = Array.prototype.filter.call(inputs, function(input) {
18+
19+
input.addEventListener('blur', function(event) {
20+
// reset
21+
input.classList.remove('is-invalid')
22+
input.classList.remove('is-valid')
23+
24+
if (input.checkValidity() === false) {
25+
input.classList.add('is-invalid')
26+
}
27+
else {
28+
input.classList.add('is-valid')
29+
}
30+
}, false);
31+
});
32+
}, false);
33+
34+
// Fetch all the forms we want to apply custom Bootstrap validation styles to
35+
var forms = document.querySelectorAll('.needs-validation');
36+
37+
// Loop over them and prevent submission
38+
Array.prototype.slice.call(forms)
39+
.forEach(function (form) {
40+
form.addEventListener('submit', function (event) {
41+
if (!form.checkValidity()) {
42+
event.preventDefault()
43+
event.stopPropagation()
44+
}
45+
46+
form.classList.add('was-validated')
47+
}, false)
48+
})
49+
50+
})()

static/styles.css

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,75 @@ main img
9696

9797
.error {
9898
max-width: max-content;
99+
}
100+
101+
/* --------------------------------------------- */
102+
/* Login/Register */
103+
/* --------------------------------------------- */
104+
105+
:root {
106+
--input-padding-x: .75rem;
107+
--input-padding-y: .75rem;
108+
}
109+
110+
.form-control {
111+
height: auto;
112+
width: 20rem!important;
113+
}
114+
115+
.form-label-group {
116+
position: relative;
117+
margin-bottom: 1rem;
118+
}
119+
120+
.form-label-group > input,
121+
.form-label-group > label {
122+
padding: var(--input-padding-y) var(--input-padding-x);
123+
}
124+
125+
.form-label-group > label {
126+
position: absolute;
127+
top: 0;
128+
left: 0;
129+
display: block;
130+
width: 100%;
131+
margin-bottom: 0;
132+
/* Override default `<label>` margin */
133+
line-height: 1.5;
134+
color: #495057;
135+
border: 1px solid transparent;
136+
border-radius: .25rem;
137+
transition: all .1s ease-in-out;
138+
}
139+
140+
.form-label-group input::-webkit-input-placeholder {
141+
color: transparent;
142+
}
143+
144+
.form-label-group input:-ms-input-placeholder {
145+
color: transparent;
146+
}
147+
148+
.form-label-group input::-ms-input-placeholder {
149+
color: transparent;
150+
}
151+
152+
.form-label-group input::-moz-placeholder {
153+
color: transparent;
154+
}
155+
156+
.form-label-group input::placeholder {
157+
color: transparent;
158+
}
159+
160+
.form-label-group input:not(:placeholder-shown) {
161+
padding-top: calc(var(--input-padding-y) + var(--input-padding-y) * (2 / 3));
162+
padding-bottom: calc(var(--input-padding-y) / 3);
163+
}
164+
165+
.form-label-group input:not(:placeholder-shown) ~ label {
166+
padding-top: calc(var(--input-padding-y) / 3);
167+
padding-bottom: calc(var(--input-padding-y) / 3);
168+
font-size: 12px;
169+
color: #777;
99170
}

templates/login.html

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/register.html

Lines changed: 16 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)