FORMS Module #34 Flashcards

1
Q

How would you create a field on a form to upload a file?

A

You can attach multiple files:

You can use a specific MIME type, like application/json or set a file extension like .pdf. Or set multiple file extensions, like this:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What happens when you specify an input type of date and or time?

A

Shows a picker. Handy!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is needed in terms of JS to intercept a form submission.

A

A form submit EVENT as below:

form.addEventListener('submit', event => {
  // submit event detected
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why is preventDefault( ) needed?

A

It prevents the unwanted reloading of the page. Here’s how to include it in the function:

const form = document.querySelector('form')
form.addEventListener('submit', event => {
  // submit event detected
  event.preventDefault()
})

At this point clicking the submit event button in the form will not do anything, except giving us the control.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Extra Credit, how do you clear a form upon submit?

A

Add an event listener listening for a click on the submit button.

document. querySelector(‘submitbtn’).addEventListener(‘click’, event =>{
document. querySelector(‘form’).reset()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly