Last active
May 21, 2025 19:58
-
-
Save johnhalsey/9471431d98e2f66a91a9989df237454d to your computer and use it in GitHub Desktop.
Javascript FormErrors utility
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
let formErrors = [] | |
export function errorsHas (key) { | |
if (formErrors.find(error => error.key == key)) { | |
return true | |
} | |
return false | |
} | |
export function errorValue(key) { | |
return formErrors.find(error => error.key == key).value | |
} | |
export function pushErrors(errors) { | |
for(let key in errors){ | |
formErrors.push({ | |
key: key, | |
value: errors[key][0] | |
}) | |
} | |
} | |
export function resetErrors() { | |
formErrors = [] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment