Skip to content

Instantly share code, notes, and snippets.

@valentincognito
Created February 12, 2020 06:07
Show Gist options
  • Save valentincognito/8c59c8bd998ca2e989918afddcab1028 to your computer and use it in GitHub Desktop.
Save valentincognito/8c59c8bd998ca2e989918afddcab1028 to your computer and use it in GitHub Desktop.
$('#my_form').submit(function(e) {
let validations = [
{
description: 'empty field',
status: $('.field').val().length != 0 ? true : false,
message: 'field xxx is empty'
}
]
let isFormValidated = true
for (let validation of validations) {
if (!validation.status) {
e.preventDefault()
alert(validation.message)
}
}
if (!isFormValidated) {
e.preventDefault()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment