-
-
Save thomseddon/4703810 to your computer and use it in GitHub Desktop.
Supporting placeholder on IE9 with AngularJS (without jQuery) > Removed jQuery dependency
> Slight optimisation in retrieving placeholder text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('test', []) | |
.directive('placeholder', function($timeout){ | |
var i = document.createElement('input'); | |
if ('placeholder' in i) { | |
return {} | |
} | |
return { | |
link: function(scope, elm, attrs){ | |
if (attrs.type === 'password') { | |
return; | |
} | |
$timeout(function(){ | |
elm.val(attrs.placeholder); | |
elm.bind('focus', function(){ | |
if (elm.val() == attrs.placeholder) { | |
elm.val(''); | |
} | |
}).bind('blur', function(){ | |
if (elm.val() == '') { | |
elm.val(attrs.placeholder); | |
} | |
}); | |
}); | |
} | |
} | |
}); |
This doesn't work with required attributes.
I tried this but it will ignore the required validation
Issue is it puts a value on the element so if a user ignores a field, it submits the value of the placeholder
I appreciate this. Thanks!
Thank you :) Works well in IE8 & IE9!
Great, thanks:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great, thanks!