New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use $(el).val()
instead of el.value
for compatibility with plugins that define custom valHooks
#323
Comments
Unfortunately a simple search-and-replace is not enough, just tried that. Would you be able to help out with a pull request? |
I actually tried before posting this issue: http://paste.pocoo.org/raw/556623/ But got stuck after some unit tests failed (specifically |
Found a viable workaround here: http://stackoverflow.com/a/9022318/281067 jQuery.validator.addMethod("placeholder", function(value, element) {
return value!=$(element).attr("placeholder");
}, jQuery.validator.messages.required); $("form").validate({
rules: {
username: {required: true, placeholder: true},
},
message: {
username: {
required: "Username required", placeholder: "Username required",
},
}
}); |
@fschroiff Cool, sounds like an idea! However, it is possible that the user enters the placeholder text as input value, in which case the jQuery Validate plugin should still use the actual value. For my specific plugin, it could be fixed using something like… (untested) jQuery.validator.addMethod('placeholder', function(value, element) {
return !$(element).hasClass('placeholder');
}, jQuery.validator.messages.required); |
Duplicate of #44 |
Example use case: mathiasbynens/jquery-placeholder#29 (comment)
In my placeholder plugin, I patch
val()
throughvalHooks
, so that it only returns the element’svalue
if the fake placeholder text is not being displayed at that point. That way, as long as you use.val()
, you get the exact same behavior as you would in a browser that has a nativeplaceholder
implementation.It would be awesome if your validation plugin would use
$(el).val()
instead ofel.value
, as it would improve compatibility with plugins like this that define customvalHooks
.The text was updated successfully, but these errors were encountered: