Design comparison
Solution retrospective
Previously done before. I decided to rewrite my old code to utilize keyUp and some other js methods for the form validation
LocalStorage is utilized as well which also checks, validates, and displays the stored values to the page on refresh.
A CRUD application of course, everything reverts back to its complete default on the continue button at the end.
This challenge a year ago was a completely motivation killer for me, but now that I got some experience, its adds some perspective and confidence of my studies in front end development.
Community feedback
- @kabir-afkPosted about 1 year ago
Hey broo, noice job persisting the data when user reloads the page , I tried working on it as well using
localStorage
but was unsuccessful for some reason . . . will definitely refer to your code . . .altho I had some concerns regarding your code . . .- Instead of
if (!userNameValidation.test(username)) { allFieldsValid = false; console.log('Username not valid'); } if (!cardNumberValidation.test(cardnumber)) { allFieldsValid = false; } if (!monthValidation.test(monthnumber)) { allFieldsValid = false; } if (!yearValidation.test(yearnumber)) { allFieldsValid = false; } if (!cvcValidation.test(cvcnumber)) { allFieldsValid = false; } if (allFieldsValid) { form.style.display = 'none'; cardThankYou.style.display = 'flex'; }
you could have done something like
if(!userNameValidation.test(username) || (!cardNumberValidation.test(cardnumber)) || (!monthValidation.test(monthnumber)) || (!yearValidation.test(yearnumber)) || (!cvcValidation.test(cvcnumber))){ allFieldsValid = false; }
- Instead of
continueBtn.addEventListener("click", () => { localStorage.removeItem('username-data'); localStorage.removeItem('cardnumber-data'); localStorage.removeItem('month-data'); localStorage.removeItem('year-data'); localStorage.removeItem('cvc-data'); form.reset(); window.location.reload(); });
you could have simply done
continueBtn.addEventListener("click", () => { localStorage.clear(); form.reset(); window.location.reload(); });
Makes for efficient code I guess . . .also this line
<p class="card-holder" id="credit-card-holder" pattern="[A-Za-z]*">Jane Appleseed</p>
shows error in console for
pattern
attribute . . . .needs some correction with regex. Also you could have added error messages on invalid form by adding empty divs and manipulating theirinnerText
on invalid input. That's all ,I guess the key to persisting data was addingwindow.onload()
eventlistener and callingaddDataToInput()
, Hope I was able to help , happy coding !!! 🥂🥂Marked as helpful0
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