Skip to content

Instantly share code, notes, and snippets.

@johnhalsey
Last active May 21, 2025 19:58
Show Gist options
  • Save johnhalsey/9471431d98e2f66a91a9989df237454d to your computer and use it in GitHub Desktop.
Save johnhalsey/9471431d98e2f66a91a9989df237454d to your computer and use it in GitHub Desktop.
Javascript FormErrors utility
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