Created
December 14, 2018 07:59
-
-
Save kitsune7/e1997e02a7bea8f5501a443282370113 to your computer and use it in GitHub Desktop.
Utility functions for displaying errors in vanilla.js (Relies on having a hidden attribute set on element at start state)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Displays in error in the first matched CSS selector given. | |
| * This relies on having a hidden attribute set on element at start state. | |
| * @param error: string The error message | |
| * @param selector: string A CSS selector that matches the element displaying the error | |
| */ | |
| function displayError (error, selector) { | |
| const errorElement = document.querySelector(selector) | |
| errorElement.innerHTML = error | |
| errorElement.removeAttribute('hidden') | |
| } | |
| /* | |
| * Removes the error message from the element and hides it again | |
| * @param selector: string A CSS selector that matches the element displaying the error | |
| */ | |
| function clearError (selector) { | |
| const errorElement = document.querySelector(selector) | |
| errorElement.innerHTML = '' | |
| errorElement.setAttribute('hidden', 'hidden') | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment