mathiasbynens/jquery-placeholder — Issue #52: Setting value programmatically doesn't change placeholder state
Author: devongovett
Created: 2012-02-10 07:21:40+00:00
State: open

If you set the value of an input programmatically using `$('input').val('something')` the value changes as expected but it still has the placeholder class. Likewise, if you set `$('input').val('')` the placeholder should appear again.

I'm not sure the best way of doing this... overwriting `jQuery.fn.val` didn't feel clean to me. jQuery also has `jQuery.valHooks` which seem like a pretty good way of doing this, but I'm not sure of their status as an API for "public consumption" at this point.

Here's the basic structure of how I'd go about it. I've also included a getter to return the real value to the user rather than the placeholder when it is applied which was my other problem with this plugin.

```javascript
jQuery.valHooks.input = jQuery.valHooks.textarea {
set: function(input, value) {
// do something...
},
get: function(input) {
// return real value (not placeholder)
}
}
```

Thanks for your work on this!
Devon