Created
March 13, 2012 17:58
-
-
Save plecong/2030292 to your computer and use it in GitHub Desktop.
jQuery Ketchup with Twitter Bootstrap
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( $ ) { | |
"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