This repository was archived by the owner on Jul 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08-feedback.js
More file actions
73 lines (54 loc) · 2.35 KB
/
Copy path08-feedback.js
File metadata and controls
73 lines (54 loc) · 2.35 KB
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
;(function () {
'use strict'
var feedbackFormOptionButtons = document.querySelector('.feedback-form-options').querySelectorAll('button')
if (!feedbackFormOptionButtons) return
feedbackFormOptionButtons.forEach((button) => {
button.addEventListener('click', selectFeedbackFormOptionButton)
})
function selectFeedbackFormOptionButton (e) {
e.stopPropagation() // trap event
feedbackFormOptionButtons.forEach((button) => {
if (button === this) {
this.classList.add('selected')
} else {
button.classList.remove('selected')
}
})
var feedbackFormText = document.querySelector('.feedback-form-text')
if (!feedbackFormText) return
feedbackFormText.classList.remove('hide')
}
var feedbackFormSubmitButton = document.querySelector('.feedback-form-submit-button')
if (!feedbackFormSubmitButton) return
var feedbackFormTextArea = document.querySelector('.feedback-form-text textarea')
if (!feedbackFormTextArea) return
feedbackFormSubmitButton.addEventListener('click', submitFeedback)
function submitFeedback (e) {
e.preventDefault()
feedbackFormSubmitButton.classList.add('selected')
var feedbackFormOptionButtonSelected = document.querySelector('.feedback-form-button.selected')
if (!feedbackFormOptionButtonSelected) return
const feedbackForm = document.querySelector('.feedback-section form')
if (!feedbackForm) return
const feedbackFormData = new FormData(feedbackForm)
feedbackFormData.set('feedback-option', feedbackFormOptionButtonSelected.value)
var action = feedbackForm.getAttribute('action') || '/'
feedbackFormData.set('feedback-page', action)
fetch(action, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams(feedbackFormData).toString(),
})
.then(() => console.log('Form successfully submitted.'))
.catch((error) => console.error('ERROR: ', error))
feedbackFormSubmitButton.innerText = 'Submitted'
feedbackFormSubmitButton.disabled = true
feedbackFormTextArea.disabled = true
feedbackFormOptionButtons.forEach((button) => {
button.disabled = true
})
var feedbackFormThankYou = document.querySelector('.feedback-form-thank-you')
if (!feedbackFormThankYou) return
feedbackFormThankYou.classList.remove('hide')
}
})()