Skip to content

Instantly share code, notes, and snippets.

@mdellavo
Created August 29, 2011 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdellavo/1178948 to your computer and use it in GitHub Desktop.
Save mdellavo/1178948 to your computer and use it in GitHub Desktop.
JQuery plugin to add error messages to form elements from an object.
(function($) {
$.fn.clearErrors = function() {
this.find('.error').removeClass('error');
this.find('.error-message').remove();
}
$.fn.addErrors = function(errors) {
var $this = this;
$.each(errors, function(k, v) {
var msg = '<span class="help-inline error-message">' + v +
'</span>';
$this
.find(':input[name="' + k +'"]')
.parent('.control-group')
.addClass('error')
.append(msg);
});
}
})(jQuery);
@webabdulla
Copy link

numbor

@webabdulla
Copy link

52

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