-
Notifications
You must be signed in to change notification settings - Fork 591
/
feed.js
102 lines (91 loc) · 3.13 KB
/
feed.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
document.addEventListener("DOMContentLoaded", () => {
const ratingCategories = [
"navigationEase",
"bookingProcess",
"accuracyInformation",
"paymentOptions",
"securityMeasures",
"customerSupport",
"overallExperience",
];
ratingCategories.forEach((category) => {
const container = document.getElementById(category);
for (let i = 1; i <= 5; i++) {
const star = document.createElement("i");
star.classList.add("fa", "fa-star", "star");
star.dataset.rating = i;
star.addEventListener("click", () => setRating(category, i));
container.appendChild(star);
}
});
});
function setRating(category, rating) {
const stars = document.querySelectorAll(`#${category} .star`);
const ratingText = document.getElementById(`${category}-rating-text`);
stars.forEach((star) => {
star.classList.toggle("checked", star.dataset.rating <= rating);
});
ratingText.textContent = `Rating: ${rating}`;
}
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("feedback-form");
form.addEventListener("submit", function (event) {
event.preventDefault(); // Prevent default form submission
// Get form elements
const eventName = document.getElementById("event_name").value.trim();
const eventDate = document.getElementById("event_date").value;
const fullName = document.getElementById("FullName").value.trim();
const email = document.getElementById("Email").value.trim();
const comments = document.getElementById("comments").value.trim();
// Check if the feedback is empty
if (comments === "" || comments.length < 4) {
Swal.fire({
icon: "error",
title: "Oops...",
text: "Please enter your feedback before submitting.",
customClass: {
popup: "swal-popup",
title: "swal-title",
content: "swal-content",
confirmButton: "swal-confirm-button",
},
});
return; // Exit the function if feedback is empty
}
// Show a success message
Swal.fire({
icon: "success",
title: "Success!",
text: "Your response has been recorded.",
customClass: {
popup: "swal-popup",
title: "swal-title",
content: "swal-content",
confirmButton: "swal-confirm-button",
},
}).then((result) => {
// Clear the feedback form after the user acknowledges the success modal
if (result.isConfirmed || result.isDismissed) {
form.reset();
// Reset star ratings
const ratingCategories = [
"navigationEase",
"bookingProcess",
"accuracyInformation",
"paymentOptions",
"securityMeasures",
"customerSupport",
"overallExperience",
];
ratingCategories.forEach((category) => {
const stars = document.querySelectorAll(`#${category} .star`);
stars.forEach((star) => {
star.classList.remove("checked");
});
const ratingText = document.getElementById(`${category}-rating-text`);
ratingText.textContent = `Rating: 0`;
});
}
});
});
});