Skip to content

Instantly share code, notes, and snippets.

@iamandycohen
Created May 24, 2013 14:36
Show Gist options
  • Save iamandycohen/5643966 to your computer and use it in GitHub Desktop.
Save iamandycohen/5643966 to your computer and use it in GitHub Desktop.
Fix jQuery Validate
// fix jquery validate reset form (this is a snippet that i created a while ago
$.extend($.validator.prototype,
{
optional: function (element) {
return !$.validator.methods.required.call(this, $.trim(element.value), element); // && "dependency-mismatch";
},
resetForm: function () {
if ($.fn.resetForm) {
$(this.currentForm).resetForm();
// fix
$(this.currentForm).find(".validation-summary-errors")
.removeClass("validation-summary-errors")
.addClass("validation-summary-valid")
.find('ul')
.empty()
.html('<li style="display:none" />');
$(this.currentForm).find(".field-validation-error")
.empty();
$(this.currentForm).find(".input-validation-error")
.removeClass("input-validation-error");
}
this.submitted = {};
this.lastElement = null;
this.prepareForm();
this.hideErrors();
this.elements().removeClass(this.settings.errorClass);
},
getLength: function (value, element) {
switch (element.nodeName.toLowerCase()) {
case 'select':
return $("option:selected", element).length;
case 'input':
if (this.checkable(element)) {
var checkedCount = 0;
this.findByName(element.name).each(function () {
if ($(this).is(':checked')) {
checkedCount++;
}
});
return checkedCount;
}
//return this.findByName(element.name).filter(':checked').length;
}
return value.length;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment