Skip to content

Commit

Permalink
Update feedback.js
Browse files Browse the repository at this point in the history
Now the form gets reset after confirmation message
  • Loading branch information
ananyag309 authored Jun 8, 2024
1 parent d45dd9d commit f475fe8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ document.addEventListener('DOMContentLoaded', () => {
const ratingTexts = document.querySelectorAll('[id$="-rating-text"]');
let currentRating = 0;

function colourStar(ind , container) {

function colourStar(ind, container) {
let s = container.querySelectorAll("span");
s = Array.from(s);
// remove existing rating
for(let i = 0; i < s.length; i++) {
for (let i = 0; i < s.length; i++) {
s[i].style.color = "white";
}

for(let i = 0; i < ind; i++) {
for (let i = 0; i < ind; i++) {
s[i].style.color = "#FFA500";
}
// console.log(container);
}

// Create 5 stars dynamically for each stars container
Expand All @@ -30,7 +28,7 @@ document.addEventListener('DOMContentLoaded', () => {
star.addEventListener('click', () => {
currentRating = i;
updateRating(index);
colourStar(i , starsContainer);
colourStar(i, starsContainer);
});

}
Expand All @@ -41,7 +39,6 @@ document.addEventListener('DOMContentLoaded', () => {
};
});


function submitFeedback() {
var feedbackInput = document.getElementById("feedback-input");
var feedback = feedbackInput.value.trim();
Expand All @@ -65,7 +62,21 @@ function submitFeedback() {
// Clear the feedback input box after the user acknowledges the success modal
if (result.isConfirmed || result.isDismissed) {
feedbackInput.value = "";
resetForm(); // Call resetForm function to reset the entire form
}
});
}

}
function resetForm() {
const starsContainers = document.getElementsByClassName("stars");
const ratingTexts = document.querySelectorAll('[id$="-rating-text"]');
let currentRating = 0;

Array.from(starsContainers).forEach((starsContainer, index) => {
const stars = starsContainer.querySelectorAll("span");
stars.forEach(star => {
star.style.color = "white"; // Reset star colors to default
});
ratingTexts[index].textContent = `Rating: ${currentRating}`; // Reset rating text
});
}

0 comments on commit f475fe8

Please sign in to comment.