Created
May 12, 2016 09:24
-
-
Save ThomasHambach/28e1adc6c5426f1b6b90ec663e93cc8b to your computer and use it in GitHub Desktop.
Angular 1.x Show Password Form Field Directive
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
<input type="password" show-password=""> |
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
'use strict'; | |
function showPassword() { | |
return { | |
scope: null, | |
restrict: 'A', | |
link: function (scope, element) { | |
var button = angular.element('<button class="show-password">Show</button>').on('click', () => { | |
button.remove(); | |
angular.element(element).attr('type', 'text'); | |
}); | |
angular.element(element).parent().append(button); | |
} | |
}; | |
} | |
angular.module('showPassword', []) | |
.directive('showPassword', showPassword); |
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
// Extending bootstrap. Style as you please. | |
button.show-password { | |
@extend .btn; | |
@extend .btn-link; | |
@extend .btn-sm; | |
position: absolute; | |
right: 0.5rem; | |
top: 2.45rem; | |
font-size: 0.6rem; | |
text-transform: uppercase; | |
padding: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment