Build a Customer Complaint Form - Build a Customer Complaint Form

Tell us what’s happening:

I have only just started this and Im trying to practice test driven development pass each test in turn, so I’m confused as to why the second test “validateForm should return an object” fails when i access the event in the validateForm function add assign the value to a variable, with the idea of using event propagation.

Your code so far

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

/* file: styles.css */

/* file: script.js */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36

Challenge Information:

Build a Customer Complaint Form - Build a Customer Complaint Form

If you need help, you’ll need to share your code with us.
Edit your post above and paste your code between the sets of triple backticks (```), where indicated.

Thankyou for your reply
It wouldnt let me edit but hopefully this works

const validateForm = (e) => {
  const key = e.target.name
 
  const validationObj =  {
    "full-name": false,
    email: false,
    "order-no": false,
    "product-code": false,
    quantity: false,
    "complaints-group": false,
    "complaint-description": false,
    "solutions-group": false,
    "solution-description": false
  };

  return validationObj ;
}

const isValid = (validationObj) => {
  return !Object.values(validationObj).includes(false)
}

const handleSubmit = () => {
}

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

form.addEventListener("keydown", e => validateForm(e))
submitBtn.addEventListener("click", handleSubmit)

Ive made no changes to the index.html or styles.css

If you scroll down past the test results in the console, you’ll see this error:

[TypeError: Cannot read properties of undefined (reading ‘target’)]

Is keydown the event you want to listen for to validate the form?

And your statements should end with semi-colons.

Thankyou for your reply, will look at these

thankyou, my event was undefined.
so ive used optional chaining

const value = e?.target.value;

also added the semi-colons and changed from keydown to change event

thankyou

ONWARDS…

1 Like