jzaefferer/jquery-validation — Issue #303: Internet Explorer HTML5 Placeholder Fix Required Method
Author: XofoSol
Created: 2012-01-13 01:02:34+00:00
State: open

Hi. I had to fix the function of the placeholder attribute to make it work in Internet Explorer 8 and 9, with a javascript function. This function take the value of the "placeholder" attribute, and inyects its value in the "value" attribute of the input. It's not a complicated script, but, because I'm adding a value to the input field, the required method is taking this value as the real value of the input and returns true. So, I had to add a few lines in the required method, besides the empty-input validation, now it makes a equal-to-placeholder validation before returning true. My fixed required method now is something like this:

required: function(value, element, param) {
// check if dependency is met
if ( !this.depend(param, element) )
return "dependency-mismatch";
switch( element.nodeName.toLowerCase() ) {
case 'select':
// could be an array for select-multiple or a string, both are fine this way
var val = $(element).val();
return val && val.length > 0;
case 'input':
if ( this.checkable(element) )
return this.getLength(value, element) > 0;
default:
var plaHol = $(element).attr('placeholder');
return $.trim(value).length > 0 && value != plaHol;
}
}