angular-placeholder
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "angular-placeholder-tai", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Placeholder shim for IE8/IE9 and styling simplification.", | ||
@@ -5,0 +5,0 @@ "author": "Tyler Akins <fidian@rumkin.com>", |
@@ -44,4 +44,14 @@ /** | ||
/** | ||
* Determine if a given type (string) is a password field | ||
* | ||
* @param {string} type | ||
* @return {boolean} | ||
*/ | ||
function isPasswordType(type) { | ||
return type && type.toLowerCase() === "password"; | ||
} | ||
return { | ||
require: "ngModel", | ||
require: "^ngModel", | ||
restrict: "A", | ||
@@ -84,2 +94,9 @@ link: function ($scope, $element, $attributes, $controller) { | ||
$controller.$formatters.unshift(function (val) { | ||
/* Do nothing on password fields, as they would | ||
* be filled with asterisks. Issue #2. | ||
*/ | ||
if (isPasswordType($element.prop("type"))) { | ||
return val; | ||
} | ||
// Show placeholder text instead of empty value | ||
@@ -86,0 +103,0 @@ return val || text; |
@@ -86,3 +86,34 @@ /*global angular, beforeEach, describe, expect, inject, it, module*/ | ||
}); | ||
describe('don\'t handle password fields', function () { | ||
var element, scope; | ||
beforeEach(module('taiPlaceholder')); | ||
beforeEach(inject(function ($rootScope) { | ||
scope = $rootScope.$new(); | ||
})); | ||
it('even if it has a placeholder', inject(function ($compile) { | ||
element = $compile('<input type="password" ng-model="something" placeholder="XYZ" />')(scope); | ||
/* Internally the code always says that placeholder | ||
* is not supported for password fields. That makes the | ||
* test the same for whether or not placeholderSupported | ||
* is true. | ||
*/ | ||
expect(element.val()).toBe(''); | ||
expect(element.hasClass('placeholder')).toBe(false); | ||
/* Changing the value on scope and then calling elemtn.val() | ||
* should provide the value from scope. | ||
*/ | ||
scope.$apply(function () { | ||
scope.something = "password"; | ||
}); | ||
expect(element.val()).toBe('password'); | ||
expect(element.hasClass('placeholder')).toBe(false); | ||
})); | ||
}); | ||
}); | ||
}()); |
{ | ||
"name": "angular-placeholder", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Placeholder shim for IE8/IE9 and styling simplification.", | ||
@@ -5,0 +5,0 @@ "author": "Tyler Akins <fidian@rumkin.com>", |
@@ -12,2 +12,8 @@ Angular Placeholder Directive | ||
Demo | ||
---- | ||
There's a [live demo](http://plnkr.co/edit/gVo2jM244jbIvMOYZocr) courtesy of Plunker. In case you want some more advanced styling, there's [another demo](http://plnkr.co/edit/D5qyFXTeGh3RV81KNeva) that helps illustrate what you can do. | ||
Browser Support | ||
@@ -26,3 +32,3 @@ --------------- | ||
<script src="angular-placeholder.js"></script> | ||
<script src="tai-placeholder.js"></script> | ||
@@ -29,0 +35,0 @@ 2. Add this somewhere to the module dependencies for your Angular application. |
24053
415
112