Skip to content

Instantly share code, notes, and snippets.

@eddiemoore
Last active January 4, 2017 06:42
Show Gist options
  • Save eddiemoore/00f56137dfd705269670b1da68a721dd to your computer and use it in GitHub Desktop.
Save eddiemoore/00f56137dfd705269670b1da68a721dd to your computer and use it in GitHub Desktop.
Simple function to check if all required fields are filled out correctly
const isFormValid = form => {
const elements = form && form.elements
if (!elements) return false
return Array.from(elements).every(elem => elem.validity && elem.validity.valid)
}
@sebdeckers
Copy link

sebdeckers commented Jan 4, 2017

@eddiemoore Throws when form is undefined but otherwise similar behaviour in the for/of style.

function isFormValid ({elements}) {
  for (const {validity} of Array.from(elements)) {
    if (validity && !validity.valid) return false
  }
  return true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment