Skip to content

Instantly share code, notes, and snippets.

@daGrevis
Created March 7, 2012 07:28
Show Gist options
  • Select an option

  • Save daGrevis/1991630 to your computer and use it in GitHub Desktop.

Select an option

Save daGrevis/1991630 to your computer and use it in GitHub Desktop.
emptyForm.js
/**
* @author daGrevis
*/
(function($) {
'use strict';
$.fn.emptyForm = function() {
return this.each(function() {
var
$self,
$inputs,
errors;
$self = $(this);
$self.click(function() {
return submitForm();
});
function submitForm() {
$inputs =
$self
.parents('form')
.find('input[type!="checkbox"][type!="radio"][type!="submit"][type!="reset"][type!="hidden"][type!="image"][type!="file"][type!="button"], textarea')
;
errors = 0;
$inputs.each(function(i, element) {
var $element;
$element = $(element);
if ($element.val() === '') {
++errors;
$element.addClass('error');
} else {
$element.removeClass('error');
}
});
return !errors;
}
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment