Skip to content

Commit

Permalink
Merge pull request #339 from amin-xiv/feeedback-length-error
Browse files Browse the repository at this point in the history
Feeedback length error checking
  • Loading branch information
multiverseweb authored Nov 13, 2024
2 parents 73fa68b + 488ce47 commit 1349aff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@
<p style="color:white">Let Me Know Your Thoughts!</p>
<input type="text" name="Name" placeholder="Your Name" required>
<input type="email" name="Email" placeholder="Your Email ID" required>
<textarea name="Message" placeholder="Your Message" rows="4" required></textarea>
<textarea name="Message" placeholder="Your Message" rows="4" required oninput="checkFeedbackLength(this)"></textarea>
<p id="feedbackError" style="color:#fd4346; opacity: 0%; font-size: 1.2rem; white-space: normal; transition: opacity 0.4s ease ">Feedback must be at least 10 characters long.</p>
<div class="star-rating" style="text-align: center; margin: 10px;">
<input type="radio" id="star5" name="rating" value="5" />
<label for="star5" title="5 star">&#9733;</label>
Expand Down
26 changes: 26 additions & 0 deletions website/scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ window.addEventListener('scroll', () => {
lastScrollTop = scrollTop;
});

window.onload = function() {
const feedbackField = document.forms['feedback-form']['Message'];

feedbackField.addEventListener('focus', () => {
checkFeedbackLength(feedbackField);
})

feedbackField.addEventListener('blur', () => {
document.getElementById('feedbackError').style.opacity = '0%';
})
}

let lastScroll = 0;
function progress() {
var scroll = this.scrollY;
Expand Down Expand Up @@ -400,6 +412,10 @@ function validateForm() {
alert("Please select a rating.");
return false;
}

if(!checkFeedbackLength(messageInput)) {
return false;
}

const formData = {
Name: nameInput.value,
Expand All @@ -417,6 +433,16 @@ function validateForm() {

return false;
}

function checkFeedbackLength(input) {
if(input.value.length < 10) {
document.getElementById('feedbackError').style.opacity = '100%';
return false;
} else {
document.getElementById('feedbackError').style.opacity = '0%';
return true;
}
}

// EMAIL VALIDATING FUNCTION
function isValidEmail(email) {
Expand Down
2 changes: 1 addition & 1 deletion website/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ footer input[type="submit"]:hover {
/* Form styling */
form {
background-color: #4c4c4c2a;
backdrop-filter: blur(10px);
backdrop-filter: blur(20px);
width: 30vw;
margin-left: -5vw;
padding: 20px;
Expand Down

0 comments on commit 1349aff

Please sign in to comment.