Created
August 29, 2011 17:54
-
-
Save mdellavo/1178948 to your computer and use it in GitHub Desktop.
JQuery plugin to add error messages to form elements from an object.
This file contains 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($) { | |
$.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); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
numbor