Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 2 years ago

Responsive Form

00YellowLemon•440
@00YellowLemon
A solution to the Intro component with sign-up form challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Hi Front-end friends. When I click submit button even when I have filled the inputs the icon still displays and the error message does not show. Feedback will be highly appreciated

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Lucas Exequiel•200
    @arrejoria
    Posted about 2 years ago

    Hi 00YellowLemon, congratulations on finishing your solution!

    I would like to help you with some tips or points that I noticed in your work.

    Here are some recommendations:

    1. [Javascript]: You're breaking the task into little functions, that's great, but you're also using a lot of variables for your dom elements. Try one variable for each form field as field__item and another as field__username.

    By doing that, you can now use a foreach for each field and do something like this.

    function handleFields() {
    const allFields = document.querySelectorAll(".field__item");
    
    allFields.forEach((field) => {
    // do something here
    if (field.value === "") {
    setError(field, `${field.placeholder} Cannot Be Empty`);
    } else {
    noError(field);
    }
    });
    }
    

    and I would handle the display of errors with a class:

    function setError(element, message) {
    let parent = element.parentElement;
    let p = parent.querySelector("p")
    p.innerText = message;
    let icon = parent.querySelector("svg");
    icon.classList.add('field__validation-show');
    p.classList.add('field__validation-show')
    }
    
    function noError(element) {
    let parent = element.parentElement;
    let svg = parent.querySelector("svg");
    let pas = parent.querySelector("p");
    svg.classList.remove('field__validation-show');
    pas.classList.remove('field__validation-show');
    }
    

    I would recommend you to use a better name for your classes and investigate more about different types and ways of selecting an element: JS Selectors

    I hope this can be of help to you

    2. [CSS]: Small detail but no less important, the container of your fields has an absolute height of 40px and overflow. It is better to use it in auto, since when the field shows the error paragraph, its height cannot be displayed.

    Doing this works for me, hope that with this you have been able to orient yourself a little!

    Thanks for sharing and I hope some of the above was helpful to you!

    keep it up you are doing great! 🧉

    Lucas,

    Marked as helpful
  • Fluffy Kas•7,655
    @FluffyKas
    Posted about 2 years ago

    Hello,

    Your error messages would show up correctly but they are being hidden by the "text" div's overflow: hidden. That piece of code isn't necessary anyway. Once you see them, you can style them up a bit. Other than this your solution looks nice.

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub