Build a Customer Complaint Form - Build a Customer Complaint Form

Tell us what’s happening:

I keep getting test 30 wrong and I can’t figure out why, any help is appreciated!! :slight_smile:
HTML and CSS unchanged

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
const form = document.getElementById("form");
const fullName = document.getElementById("full-name");
const email = document.getElementById("email");
const orderNo = document.getElementById("order-no");
const productCode = document.getElementById("product-code");
const quantity = document.getElementById('quantity');

const complaintTypes = document.getElementById("complaints-group");
const complaintDescription = document.getElementById("complaint-description");
const complaintGroup = complaintTypes.querySelectorAll('input[type="checkbox"]');

const solutionTypes = document.getElementById("solutions-group");
const solutionDescription = document.getElementById("solution-description");
const solutionGroup = solutionTypes.querySelectorAll('input[type="radio"]');

const damagedProduct = document.getElementById("damaged-product");
const nonconforming = document.getElementById("nonconforming-product");
const delayedDispatch = document.getElementById("delayed-dispatch");

const refund = document.getElementById("refund");
const exchange = document.getElementById("exchange");
const otherComplaint = document.getElementById("other-complaint");
const otherSolution = document.getElementById("other-solution");


const submitBtn = document.getElementById("submit-btn");

const emailRegex = /.+@.+[.org|.com]/;
const orderNoRegex = /^2024\d{6}$/;
const productCodeRegex = /[\w|\W]{2}[\d]{2}-[\w|\W][\d]{3}-[\w|\W]{2}[\d]/;




const validateForm = () => {
  const complaintObject = {
    "full-name": fullName.value ? true : false,
    "email": emailRegex.test(email.value),
    "order-no": orderNoRegex.test(orderNo.value),
    "product-code": productCodeRegex.test(productCode.value),
    "quantity": quantity.value > 0 ? true: false,
    "complaints-group": Array.from(complaintGroup).some((item) => item.checked),
    "complaint-description": otherComplaint.checked && complaintDescription.value.length >= 20 || damagedProduct.checked || nonconforming.checked || delayedDispatch.checked ? true: false,
    "solutions-group": Array.from(solutionGroup).some(item => item.checked),
    "solution-description": otherSolution.checked && solutionDescription.value.length >= 20 || refund.checked || exchange.checked  ? true: false
  };

 
 return complaintObject 
}; 
 
  
const isValid = (obj) => Object.keys(obj).every((item) => item === true);

console.log(isValid(validateForm()));
 

 
fullName.addEventListener("change", () => { 
  const valid = validateForm()
 valid["full-name"] ? fullName.style.borderColor = "green" : fullName.style.borderColor = "red"
    }); 
email.addEventListener("change", () => { 
  const valid = validateForm()
 valid["email"] ? email.style.borderColor = "green" : email.style.borderColor = "red"
  });
orderNo.addEventListener("change", () => {
   const valid = validateForm()
 valid["order-no"] ? orderNo.style.borderColor = "green" : orderNo.style.borderColor = "red"
  });
productCode.addEventListener("change", () => {
  const valid = validateForm()
 valid["product-code"] ? productCode.style.borderColor = "green" : productCode.style.borderColor = "red"
  });
quantity.addEventListener("change", () => {
   const valid = validateForm()
 valid["quantity"] ? quantity.style.borderColor = "green" : quantity.style.borderColor = "red"
  });

complaintDescription.addEventListener("change", () => {
   const valid = validateForm()
 valid["complaint-description"] ? complaintDescription.style.borderColor = "green" : complaintDescription.style.borderColor = "red"
  });

solutionDescription.addEventListener("change", () => {
   const valid = validateForm()
 valid["solution-description"] ? solutionDescription.style.borderColor = "green" : solutionDescription.style.borderColor = "red"
  });

 complaintTypes.addEventListener("change", () => {
     const valid = validateForm()
complaintTypes.style.borderColor = valid["complaints-group"] ? "green" : "red";
 });
 solutionTypes.addEventListener("change", () => {
      const valid = validateForm()
solutionTypes.style.borderColor = valid["solutions-group"] ? "green" : "red";
 });

form.addEventListener("submit", (e) => {
  
   if(!isValid(validateForm())){
     e.preventDefault()
     alert("fill out all required areas")
   }else if(isValid(validateForm())) {
     alert("your form has been submitted")
   }
  });

Your browser information:

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

Challenge Information:

Build a Customer Complaint Form - Build a Customer Complaint Form

When I try your form, it always asks me to fill out the required fields even though I think they are all filled out correctly.
Have you tried to fill it out and test?
What values did you use? (I can try the same ones and let u know if I did something different on my end)

All the values are highlighted green when I fill it out. When you say “values” are you just talking about what I type in the inputs to test the form? because this is what I have been using
Full Name:
Joe
Email Address:
joejoe@sadsdf.com

Order No:
2024562314
Product Code:
fg12-n123-fr1
Quantity:
2
Complaint Reason:
Damaged Product
Nonconforming Product
Delayed Dispatch
Other
Description of Complaint Reason
fsdfdsfdfgdfgdfgdfgdfgdfgdfg
Desired Solution
Refund Exchange Other
Description of Desired Solution
dfgdfgdfgfdgdfgdfgdfgdfgdfg

on the checkboxes and radio buttons I have tried the “other” options on both and it seems to work fine. I also tried the other boxes and buttons as well and it highlights green. But initially that is where I thought the problem was, was with this code.

 "complaints-group": Array.from(complaintGroup).some((item) => item.checked),
    "complaint-description": otherComplaint.checked && complaintDescription.value.length >= 20 || damagedProduct.checked || nonconforming.checked || delayedDispatch.checked ? true: false,
    "solutions-group": Array.from(solutionGroup).some(item => item.checked),
    "solution-description": otherSolution.checked && solutionDescription.value.length >= 20 || refund.checked || exchange.checked  ? true: false

but now I am thinking maybe it is with my form.addEventlistener function… I am not sure though :grimacing:

yeah I’m not sure why I can’t get it to accept what I type.
(it always alerts that I should fill out the required areas)
Here’s a screen shot of everything I filled out:

Look carefully at what this code is doing.

thank you! that fixed it! :slight_smile: