Complete these steps to create a 'signin' prototype:
- "Listen" for when the user
click
s the#signin
button,display
the#modal
window - "Listen" for when the user
click
s the#close
button,display
(or fade out) out the#modal
window - "Listen" for when the user
click
s the#submit
button, add an.error
class to bothinput.field
elements- Easy: First add the
.error
class to each individually usinggetElementById()
orquerySelector()
- Advanced: Once successful, try applying to both
input.field
usingquerySelectorAll()
and aforEach()
(or another type of traversal loop)
- Easy: First add the
- Remove the
.error
class from any individual<input>
when the cursor gives itfocus
- Easy: First try writing one event listener/handler per input element
- Advanced: Then do this by writing only ONE event listener/handler for all input elements and applying it using a traversal loop
- In
index.html
change the#submit
element fromtype="button"
totype="submit"
. When the user triggers asubmit
Event
for theform#getstarted
, prevent the form from proceeding with it's default behavior (which is redirecting away from the page)- Remove the
click
listener from thebutton#submit
created earlier and move the logic within it to this listener
- Remove the
- On submit of the
form#getstarted
, only add the.error
class to theinput.field
elements that have avalue
of""
(blank, meaning any content within the field will prevent an error)- Consider what should if the user just adds spaces to the field? Compare
" " == ""
in your console to test; then find a function that will trim the white spaces from a String to help validate this field
- Consider what should if the user just adds spaces to the field? Compare
- Prototype the form validation by checking the two
input.fields
onsubmit
of theform#getstarted
. If both fields are "valid" (they not blank, not including "white space" characters), do the following:- Remove the
#modal
from view - Remove the
button#signin
from view - Append
textContent
to the#hello
heading so it reads "Welcome, [USERNAME]" - Change the
font-size
of the#hello
heading so that it's half the current size - Consider the various ways we could validate both fields, including the use of a
Boolean
variable as atrue
orfalse
status flag
- Remove the
- Try improving the user experience by adding/removing the
.error
class from aninput.field
immediately after the cursor leaves one of the individual<input>
(rather than waiting for asubmit
event to occur)- Consider the
blur
(opposite of focus) can be added individually to eachinput
, but should be done so by writing one event listener/callback function and using a loop to apply to each of theinput.field
elements at the same time
- Consider the
- Allow the user to
click
the dark translucent background of the#modal
block to have it close itself (but not the the form within it)- Test this and see what happens when an element inside of another element (here, the
form
within the.modal
) is clicked. Click events will "bubble" (propagate) up the DOM tree! - Search for a way to stop an event (clicking the
<form>
) frombubbling
to its parent (the.modal
)
- Test this and see what happens when an element inside of another element (here, the