Build a Customer Complaint Form - Build a Customer Complaint Form

Tell us what’s happening:

I think I broke it. Sooooo, I was trying to evaluate whether or not certain objectives were meet and the site basically said “no”.

All I changed was putting the form event listener into the isValid function and shortening the submitBtn event listener to:
submitBtn.addEventListener(“click”, isValid(validateForm()))"
instead of:
“submitBtn.addEventListener(“click”, ()=>{
console.log(validateForm())
isValid(validateForm())
})”
Can someone tell me what I did wrong?

Your code so far

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

/* file: styles.css */

/* file: script.js */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0

Challenge Information:

Build a Customer Complaint Form - Build a Customer Complaint Form

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-customer-complaint-form/67279fe50237291f80eed8b8.md at main · freeCodeCamp/freeCodeCamp · GitHub

Apologies the script didn’t follow over. I’ll put it in the replies for now.

const fullName = document.getElementById(“full-name”);

const email = document.getElementById(“email”);

const orderNum = document.getElementById(“order-no”);

const productCode = document.getElementById(“product-code”);

const quantity = document.getElementById(“quantity”);

const complaintGroup = document.getElementById(“complaints-group”);

const complaintDescr = document.getElementById(“complaint-description”);

const solutionGroup = document.getElementById(“solutions-group”);

const solutionDescr = document.getElementById(“solution-description”);

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

//Use .checked for boolean result

const damaged = document.getElementById(“damaged-product”);

const noncon = document.getElementById(“nonconforming-product”);

const delayed = document.getElementById(“delayed-dispatch”);

const ComplOther = document.getElementById(“other-complaint”);

const refund = document.getElementById(“refund”);

const exchange = document.getElementById(“exchange”);

const solutionOther = document.getElementById(“other-solution”);

const transitionObj = {

'full-name':fullName, 

'email':email, 

'order-no':orderNum, 

'product-code':productCode,

'quantity':quantity,

'complaints-group': complaintGroup,

'complaint-description':complaintDescr,

'solutions-group': solutionGroup,

'solution-description':solutionDescr

}

function validateForm(){

let formObj = {

    'full-name':false, 

    'email':false, 

    'order-no':false, 

    'product-code':false,

    'quantity':false,

    'complaints-group':false,

    'complaint-description':true,

    'solutions-group':false,

    'solution-description':true

}

if(fullName.value !== null && fullName.value !== undefined && fullName.value.length >=1){

    console.log(fullName.value.length)

    console.log(fullName.value)

    console.log(typeof fullName.value)

   formObj\["full-name"\]=true

}




if(email.checkValidity() && email.value !== null && email.value !== undefined && email.value.length > 1){

    formObj\["email"\] = email.checkValidity()

}

if(orderNum.checkValidity() && orderNum.value !== null && orderNum.value !== undefined && orderNum.value.length > 1 ){

    formObj\["order-no"\] = orderNum.checkValidity()

}

if(productCode.checkValidity() && productCode.value !== null && productCode.value !== undefined && productCode.value.length > 1 ){

    formObj\["product-code"\] = productCode.checkValidity()

}

console.log(quantity)

if(quantity.value > 0 && /\[1-9\]+/gi.test(quantity.value) && !/\[a-z\]/gi.test(quantity.value)){

    formObj\["quantity"\] = true

}

if(damaged.checked||noncon.checked||delayed.checked||ComplOther.checked){

    formObj\["complaints-group"\] = true

}

if(!ComplOther.checked && complaintDescr.value.length > 20 || ComplOther.checked && complaintDescr.value.length < 20){

    formObj\["complaint-description"\] = false

}

if(refund.checked||exchange.checked||solutionOther.checked){

    formObj\["solutions-group"\] = true

}

if(!solutionOther.checked && solutionDescr.value.length > 20 || solutionOther.checked && solutionDescr.value.length < 20){

    formObj\["solution-description"\] = false

}




return formObj

}

function isValid(obj){

Object.keys(obj).forEach(key => {

    let el = transitionObj\[key\]

    if(obj\[key\]==true){

        el.style.borderColor = "green"

    }

    else{

        el.style.borderColor = "red"

    }

})

form.addEventListener("change", ()=>{

    isValid(validateForm())

})

}

submitBtn.addEventListener(“click”, isValid(validateForm()))

/* Patterns

email: “.+@.+\.(com|gov|org|io|co)”

order-no: “2024\d{6}”

product-code: “[a-zA-Z][a-zA-Z]\d\d-[a-zA-Z]\d\d\d-[a-zA-Z][a-zA-Z]\d”

*/

<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">
<h1>Complaint Form</h1>

<form id="form">

    <fieldset id="personal-info">

        <div>

            <label for="full-name">Full Name:</label>

            <input required 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" pattern="/^\[a-zA-Z0-9.\_%+-\]+@\[a-zA-Z0-9.-\]+\\.\[a-zA-Z\]{2,}$/">

        </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######"

            pattern="2024\\d{6}">

        </div>

        <div>

            <label for="product-code">Product Code:</label>

            <input type="text" id="product-code" name="product-code" placeholder="XX##-X###-XX#" pattern="\[a-zA-Z\]\[a-zA-Z\]\\d\\d-\[a-zA-Z\]\\d\\d\\d-\[a-zA-Z\]\[a-zA-Z\]\\d">

        </div>

        <div>

            <label for="quantity">Quantity:</label>

            <input type="number" id="quantity" name="quantity" min="1">

        </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>



    <fieldset id="complaint-description-container">

        <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>

    </fieldset>



    <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>



    <fieldset id="solution-description-container">

        <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>

    </fieldset>

    <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>

Please format your code to make it readable

There are two ways you can format your code to make it easier to read and test:

  1. After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)

  1. Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.

To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor: