createElement, insertAdjacentElement, for loop
Design comparison
Solution retrospective
I'm not super happy with the functionality. I've been stuck on the validation.
- If a user misses a field, they get an error. However, if they correct that error, I can't get the newly created element to disappear. Any help there?
- Similar to my first question, I can't get the field border to change if the user fixes any errors. I can get the font color to change back correctly, but not the border.
- Because I'm using createElement to get my error Icons & error spans, when they get created, they're bumping the rest of the form fields. Initially I had them all just visibility: hidden, changing to visibility: visible. How do I avoid the content bump?
- Again, sort of going off the question above, if a user misses a field multiple times, the submit button keeps generating errors over and over again. How can I only allow errors to show up once?
Community feedback
- @arthur-lagePosted over 2 years ago
Hello again, I cloned your github project and tried to do this, it worked correctly. I used the following code:
const clearErrors = () => { document.querySelectorAll(".error").forEach((error) => { error.remove(); }); }; checkInputs = () => { clearErrors(); displayErrorSpans(); displayErrorIcons(); };
Marked as helpful1@marissahuysentruytPosted over 2 years ago@arthur-lage ok yes. I figured remove() would come into play, but I must not have implemented it correctly. I just needed an extra function!!! Thank you SO MUCH!!!!
1 - @arthur-lagePosted over 2 years ago
Hi! I loved your project, and I'll try to answer some of your questions.
1 and 4 - An easy way to solve these problems would be deleting all the error elements when validating the form, and checking for errors again and showing them if necessary. When creating the new error elements, make sure to give them classes, so it will be easy to keep track of them and delete them when necessary.
Marked as helpful1@marissahuysentruytPosted over 2 years ago@arthur-lage Thank you! I'll have to experiment with your advice. Maybe I need an extra if statement somewhere? To check on the error classes, like you said.
Thanks :)
1
Please log in to post a comment
Log in with GitHubJoin 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