Last active
August 29, 2015 14:25
-
-
Save saxap/2dab9493ec6bdae987a9 to your computer and use it in GitHub Desktop.
simple bootstrap form validation on jquery
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
| function checkErrors(el) { | |
| var errors = false | |
| el.find('input, textarea').each(function(){ | |
| if ($(this).val() == '') { | |
| $(this).closest('.form-group').addClass('has-error'); | |
| errors = true; | |
| } else { | |
| $(this).closest('.form-group').removeClass('has-error'); | |
| } | |
| }); | |
| if (errors) return true; | |
| else return false; | |
| } | |
| ////////// | |
| $('form').submit(function(e){ | |
| var form = $(this); | |
| if (checkErrors(form)) return false; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment