Build a Customer Complaint Form - Build a Customer Complaint Form

Tell us what’s happening:

Hi, when I submit the form, the input and fieldset borders appear to be set correctly. I’ve completed all the steps, but I can’t get past step 24.
Can you help me figure out what I’m doing wrong?

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Customer Complaint Form</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <h1>Complaint Form</h1>
    <form id="form">
        <fieldset id="personal-info">
            <div>
                <label for="full-name">Full Name:</label>
                <input type="text" id="full-name" name="full-name" placeholder="John Doe" >
            </div>

            <div>
                <label for="email">Email Address:</label>
                <input type="email" id="email" name="email" placeholder="example@domain.com">
            </div>
        </fieldset>
        <hr>
        <fieldset id="product-info">
            <div>
                <label for="order-no">Order No:</label>
                <input type="text" id="order-no" name="order-no" placeholder="2024######">
            </div>
            <div>
                <label for="product-code">Product Code:</label>
                <input type="text" id="product-code" name="product-code" placeholder="XX##-X###-XX#">
            </div>
            <div>
                <label for="quantity">Quantity:</label>
                <input type="number" id="quantity" name="quantity" min="1" pattern="/[1-9]+/">
            </div>
        </fieldset>

        <fieldset id="complaints-group">
            <legend>Complaint Reason:</legend>
            <div>
                <input type="checkbox" id="damaged-product" name="complaint" value="damaged-product">
                <label for="damaged-product">Damaged Product</label>
            </div>

            <div>
                <input type="checkbox" id="nonconforming-product" name="complaint" value="nonconforming-product">
                <label for="nonconforming-product">Nonconforming Product</label>
            </div>

            <div>
                <input type="checkbox" id="delayed-dispatch" name="complaint" value="delayed-dispatch">
                <label for="delayed-dispatch">Delayed Dispatch</label>
            </div>

            <div>
                <input type="checkbox" id="other-complaint" name="complaint" value="other">
                <label for="other-complaint">Other</label>
            </div>
        </fieldset>

        <div id="complaint-description-container" class="hide">
            <legend>Description of Complaint Reason</legend>
            <textarea placeholder="Describe the reason of your complaint in at least 20 characters"
                name="complaint-textarea" id="complaint-description"></textarea>
        </div>

        <fieldset id="solutions-group">
            <legend>Desired Solution</legend>
            <input type="radio" name="solutions" id="refund" value="refund">
            <label for="refund">Refund</label>

            <input type="radio" name="solutions" id="exchange" value="exchange">
            <label for="exchange">Exchange</label>

            <input type="radio" name="solutions" id="other-solution" value="other">
            <label for="other-solution">Other</label>
        </fieldset>

        <div id="solution-description-container" class="hide">
            <legend>Description of Desired Solution</legend>
            <textarea placeholder="Describe the desired solution to your issue in at least 20 characters"
                name="solution-textarea" id="solution-description"></textarea>
        </div>
        <div id="btn-container">
            <button type="submit" id="submit-btn">Submit</button>
            <span id="message-box" aria-live="polite"></span>
        </div>

    </form>

    <script src="script.js"></script>
</body>

</html>
/* file: styles.css */
* {
    box-sizing: border-box;
}

h1 {
    text-align: center;
}

#form {
    max-width: 70%;
    margin: auto;
    border-radius: 10px;
    box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
    padding: 10px;
}

input {
    border-color: rgb(118, 118, 118);
}

#personal-info input, #product-info input {
    width: 100%;
    margin-bottom: 10px;
}


fieldset {
    margin-bottom: 10px;
    border-radius: 5px;
    border-color: rgb(118, 118, 118);
}

textarea {
    max-width: 100%;
    width: 100%;
    border-color: rgb(118, 118, 118);
}

#btn-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#submit-btn, #clear-btn {
    margin: 10px 15px 0;
}

.hide {
    display: none;
}
/* file: script.js */
const form = document.getElementById("form");
const nameInput = document.getElementById("full-name");
const emailInput = document.getElementById("email");
const orderNo = document.getElementById("order-no");
const productCode = document.getElementById("product-code");
const quantity = document.getElementById("quantity");
const checkboxInputs = document.querySelectorAll('input[type="checkbox"]')
const otherCheckbox = document.getElementById("other-complaint");
const complaintDescription = document.getElementById("complaint-description");
const radioInputs = document.querySelectorAll('input[type="radio"]')
const otherRadio = document.getElementById("other-solution");
const solutionDescription = document.getElementById("solution-description");
 

const regexName = /^(?:|\s+)$/
const regexEmail = /^.+@.+\.com$/i
const regexOrderNo = /^2024\d{6}$/
const regexProductCode = /^[a-zA-Z]{2}\d{2}-[a-zA-Z]\d{3}-[a-zA-Z]{2}\d$/
const regexQuantity = /^[1-9]+$/

 
function checkTextarea (elementInput, textAreaInput) {
  if (elementInput.checked) { 
      textAreaInput.parentElement.classList.remove("hide") 
      const regexTextArea = /.{20}/s
      return regexTextArea.test(textAreaInput.value) 
    }
    textAreaInput.parentElement.classList.add("hide") 
    return false
}

function validateForm () {
  const valideObj = {
    "full-name": !regexName.test(nameInput.value),
    "email": regexEmail.test(emailInput.value),
    "order-no": regexOrderNo.test(orderNo.value),
    "product-code": regexProductCode.test(productCode.value),
    "quantity": regexQuantity.test(quantity.value),
    "complaints-group": Array.from(checkboxInputs).some((checkbox) => {if(checkbox.checked) {
    return true
   }}),
    "complaint-description": checkTextarea (otherCheckbox,complaintDescription),
    "solutions-group": Array.from(radioInputs).some((radio) => {if(radio.checked) {
    return true
   }}) ,  
    "solution-description": checkTextarea (otherRadio, solutionDescription) 
  } 

  if (otherCheckbox.checked === false) {
    delete valideObj["complaint-description"]
  }
  if (otherRadio.checked === false) {
    delete valideObj["solution-description"]
  }
  return valideObj
}  


function setBorderColorInput (input) { 
  for (const prop in validateForm ()) { 
    if(prop === input.id) {
      validateForm ()[input.id]? input.style.borderColor = "green": input.style.borderColor = "red";
    } 
    if (prop === input.parentElement.id) {
        validateForm ()[input.parentElement.id]? input.parentElement.style.borderColor = "green": input.style.borderColor = "red";
    } 
    if (prop === input.parentElement.parentElement.id) {
        validateForm ()[input.parentElement.parentElement.id]? input.parentElement.parentElement.style.borderColor = "green": input.parentElement.parentElement.style.borderColor = "red"
    }  
  }
} 

form.addEventListener("change", (event) => {setBorderColorInput(event.target)} )

function isValid (obj) {
  for (const prop in obj) { 
    if (obj[prop] === false) {
      return false
    } 
  }
  return true 
}


form.addEventListener("submit",() => {console.log(isValid(validateForm()))
  for (const prop in validateForm ()) {
    let element = document.getElementById(prop) 
    setBorderColorInput (element)
  }
})


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36

Challenge Information:

Build a Customer Complaint Form - Build a Customer Complaint Form

Where in your code are you validating solution-group?

I’m validating “solutions-group” in this part of code:

function validateForm () {
  const valideObj = {
    "full-name": !regexName.test(nameInput.value),
    "email": regexEmail.test(emailInput.value),
    "order-no": regexOrderNo.test(orderNo.value),
    "product-code": regexProductCode.test(productCode.value),
    "quantity": regexQuantity.test(quantity.value),
    "complaints-group": Array.from(checkboxInputs).some((checkbox) => {if(checkbox.checked) {
    return true
   }}),
    "complaint-description": checkTextarea (otherCheckbox,complaintDescription),
    "solutions-group": Array.from(radioInputs).some((radio) => {if(radio.checked) {
    return true
   }}) ,  
    "solution-description": checkTextarea (otherRadio, solutionDescription) 
  } 

  if (otherCheckbox.checked === false) {
    delete valideObj["complaint-description"]
  }
  if (otherRadio.checked === false) {
    delete valideObj["solution-description"]
  }
  return valideObj
}

Specifically in the value of the “solution-group” property of the valideObj

Why are you hiding complaint and solution descriptions until the “other” checkbox/radio is selected? Someone filling out the form might reasonably want to elaborate on how a product was damaged, etc.

Also, you might want to test this locally rather than in the fCC environment, so you can see what happens when your form is incomplete and you click the submit button.

that’s exactly how the example project works

So it does! Interesting.