Skip to content

Instantly share code, notes, and snippets.

@SlyNet
Created March 14, 2012 13:01
Show Gist options
  • Save SlyNet/2036300 to your computer and use it in GitHub Desktop.
Save SlyNet/2036300 to your computer and use it in GitHub Desktop.
Making asp.net validation work with twitter bootstrap
$.validator.setDefaults({
highlight: function (element) {
$(element).closest(".control-group").addClass("error");
},
unhighlight: function (element) {
$(element).closest(".control-group").removeClass("error");
}
});
$(function () {
$('span.field-validation-valid, span.field-validation-error').each(function () {
$(this).addClass('help-inline');
});
$('form').submit(function () {
if ($(this).valid()) {
$(this).find('div.control-group').each(function () {
if ($(this).find('span.field-validation-error').length == 0) {
$(this).removeClass('error');
}
});
}
else {
$(this).find('div.control-group').each(function () {
if ($(this).find('span.field-validation-error').length > 0) {
$(this).addClass('error');
}
});
}
});
$('form').each(function () {
$(this).find('div.control-group').each(function () {
if ($(this).find('span.field-validation-error').length > 0) {
$(this).addClass('error');
}
});
});
})
@kk0239
Copy link

kk0239 commented Aug 13, 2014

@SlyNet do u have an example?

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