Compatibility with jQuery validation
mathiasbynens opened this issue · 2 comments
mathiasbynens commented
The jQuery validation plugin uses element.value
, and not $element.val()
, so the valHooks
don’t kick in. I filed jquery-validation/jquery-validation#323 asking to change this for better compatibility with plugins that define custom valHooks
.
dfw commented
Hi Mathias,
Is there a workaround for this? I'm having issues in IE where $("#FirstName").val = "" and element.value = "First Name". I'm suing the jQuery validation plugin. Should I run some code before validation occurs to clear out the values?
gavinengel commented
I'm a bit confused by references here... is this issue resolved?
By the way, one way to deal with the issue is to use a custom jqv rule:
/**
* Wraps a core jQV rule to make it safe in IE8
* example usage:
*
* //email: true, // comment out original
* ignorePlaceholder: { rule: 'email', params: true } // add this new IE8 safe rule
*
*/
$.validator.addMethod("ignorePlaceholder", function (value, element, params) {
var isValid = true;
if ($(element).val() && $(element).val() != $(element).attr('placeholder')) {
$.validator.messages.ignorePlaceholder = $.validator.messages[params.rule];
isValid = $.validator.methods[params.rule].call( this, element.value.replace(/\r/g, ""), element, params.params );
}
return isValid;
}, $.validator.messages.ignorePlaceholder);