From a65a624dfc9d7eb7ef06d9d3e456501a04cf9b2f Mon Sep 17 00:00:00 2001 From: Robert McGovern Date: Thu, 29 Sep 2022 10:01:45 +0100 Subject: [PATCH] forgot to commit javascript changes, so added in check for in error visible before attempting to remove CSS class --- .../js/script.js | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/projects/FrontendMentor/newbie/intro-component-with-signup-form/js/script.js b/projects/FrontendMentor/newbie/intro-component-with-signup-form/js/script.js index 573768e..a237a0a 100644 --- a/projects/FrontendMentor/newbie/intro-component-with-signup-form/js/script.js +++ b/projects/FrontendMentor/newbie/intro-component-with-signup-form/js/script.js @@ -20,10 +20,12 @@ function checkFormValidity(event) { // console.log(`${input.id} is invalid`); // console.log(`${input.id} msg ${input.validationMessage}`); // get the relevant error message element, using id of the input - let errorSection = document.getElementById(`errorMessage-${input.id}`) + let errorSection = document.getElementById( + `errorMessage-${input.id}` + ); // console.log(`ES: ${errorSection}, ${typeof (errorSection)} id: ${errorSection.id}`); - errorSection.removeAttribute("hidden"); - input.classList.add("error-highlight") + errorSection.hidden = false; + input.classList.add("error-highlight"); } } } @@ -32,8 +34,15 @@ function checkFormValidity(event) { // I could more ideally check if the class is in the classlist, // and attribute hidden was false function inputFocused(event) { + /** + * Just for VS Code intellisense + * + * @type {HTMLInputElement} + */ const input = event.currentTarget; - input.classList.remove("error-highlight"); - let errorSection = document.getElementById(`errorMessage-${input.id}`); - errorSection.setAttribute("hidden", true); -} \ No newline at end of file + if (input.classList.contains("error-highlight")) { + input.classList.remove("error-highlight"); + let errorSection = document.getElementById(`errorMessage-${input.id}`); + errorSection.hidden = true; + } +}