Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

My first sign-up form

Lia Marie• 80

@lmestrella

Desktop design screenshot for the Intro component with sign-up form coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

Solution retrospective


Any tips on organizing js code/files? Right now I only use 1 file for everything since I have no idea how it's supposed to be in a professional setup. Thank you!

Community feedback

@aminetoro

Posted

I visited your webpage , you have to make the width of boxes or blocks 100% when the screen is small

1

@aminetoro

Posted

you asked for organizing js code, the best way is to use modules using Immediately Invoked Function Expression (IIFE) and closures, but i think this proj doesn't need that, it has a single function only, but for the big projects, you should use modules to make js code cleaner and easy for debbuging

1

Lia Marie• 80

@lmestrella

Posted

@aminetoro Thanks for the advice! Everything you said is new to me so I have no idea where to start. I will look into it tomorrow. :)

0

@aminetoro

Posted

@lmestrella https://www.udemy.com/course/the-complete-javascript-course/

0
Lia Marie• 80

@lmestrella

Posted

@aminetoro Thank you!

0

@aminetoro

Posted

Hi, You did a great job, please I have a question, I have a problem with insertAdjacentHtml, the first that shows text error works correctly, but the second doesn't work (erroricon) appear only in the last input

document.querySelector('form').addEventListener('submit',(e)=>{
    e.preventDefault();
    /* image selection */
    const errorimg = document.createElement('img');
    errorimg.src = './images/icon-error.svg';
    errorimg.classList.add('errorimg');
    /* select input values */
    const infoForm = [...e.target];
    /* select input Names */
    const errornames = infoForm.map((el)=>{console.log(el.name)});
    /* delete error messages */
    if(document.querySelectorAll('.formaterror')){
        document.querySelectorAll('.formaterror').forEach(el=>{
              el.remove();
        })
    }
    if(document.querySelectorAll('.errorimg')){
        document.querySelectorAll('.errorimg').forEach(el=>{
              el.remove();
        })
    }
    /* loop trough array to handle errors */
    infoForm.forEach((el,index)=>{
        const elvalue = el.value; 
        if(!elvalue){
        const errormsg = `${el.name} cannot be empty`;
        const error = document.createElement('div');
        error.classList.add('formaterror');
        error.innerHTML = errormsg;
        document.forms[0].querySelectorAll('.form-control')[index].insertAdjacentElement('afterbegin',errorimg);
        document.forms[0].querySelectorAll('.form-control')[index].insertAdjacentElement('afterend',error);
        
        }else if(el.classList[0] === 'email'){
            if(!validateEmail(el.value)){
        const errormsg = `Looks like an invalid email`;
        console.log('ami');
        const error = document.createElement('div');
        error.classList.add('formaterror');
        error.innerHTML = errormsg;
        document.forms[0].querySelectorAll('.form-control')[index].insertAdjacentElement('afterend',error);
        document.forms[0].querySelectorAll('.form-control')[index].insertAdjacentElement('afterbegin',errorimg);
                }
        }else{
           /* insert Element into  */

        }
        
    })
    
    /* regular expression function for email */
    function validateEmail(email){
        const re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    }
})   

please, Help me, I'm stuck, 2 days ago !!!

0

Lia Marie• 80

@lmestrella

Posted

@aminetoro Hello! Thank you for leaving a comment. Can you provide a repo of your project? If it's possible I'd like to help you debug your code.

1

@aminetoro

Posted

@lmestrella https://github.com/aminetoro/newbie-form-purple.git

0

@aminetoro

Posted

@lmestrella live vercel : https://newbie-form-purple.vercel.app/

0
Lia Marie• 80

@lmestrella

Posted

@aminetoro Okay, so I found out that the insertAdjacentElement() moves the erroricon element from its previous position on to the new one, that's why the erroricon element only shows up in the last position.

You need to clone it to make it work:

document.forms[0]
        .querySelectorAll(".form-control")
        [index].insertAdjacentElement("afterbegin", errorimg.cloneNode());

I got the idea from the Node.appendChild() method since they act similar. It's stated in the [documentation] (https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild).

1

@aminetoro

Posted

@lmestrella Thanks a Lot !!!

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord