Skip to content

Instantly share code, notes, and snippets.

@plecong
Created March 13, 2012 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save plecong/2030292 to your computer and use it in GitHub Desktop.
Save plecong/2030292 to your computer and use it in GitHub Desktop.
jQuery Ketchup with Twitter Bootstrap
!function( $ ) {
"use strict"
$.ketchup
.createErrorContainer(function(form, el) {
var g = el.closest('.controls');
if (g) {
return $('<ul/>', {
'class': 'help-block'
}).appendTo(g);
} else {
return $('<ul/>', {
'class': 'help-inline'
}).insertAfter(g);
}
})
.addErrorMessages(function(form, el, container, messages) {
container.empty();
for(i = 0; i < messages.length; i++) {
$('<li/>', { text: messages[i] }).appendTo(container);
}
})
.showErrorContainer(function(form, el, container) {
container
.closest('.control-group').addClass('error');
container.show()
})
.hideErrorContainer(function(form, el, container) {
container
.closest('.control-group').removeClass('error')
container.hide()
})
.helper('inputsWithNameNotSelf', function(form, el) {
return this.inputsWithName(form, el).filter(function() {
return ($(this) != el);
});
})
$(function () {
$('form[data-validate="ketchup"]').ketchup()
})
}( window.jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment