Skip to content

Commit

Permalink
Merge pull request #20 from kristerkari/fix-issue-19
Browse files Browse the repository at this point in the history
Don't call showPlaceholder method when element has a password clone, fixes #19
  • Loading branch information
Krister Kari committed Jun 9, 2015
2 parents 3fc2087 + f685ae8 commit 4b1759b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

function checkForPlaceholder(element) {
var placeholder = utils.getPlaceholderValue(element);
var clone;

if (!placeholder) {
return;
Expand All @@ -75,7 +76,7 @@
} else {

if (elems.hasPasswordClone(element)) {
var clone = elems.getPasswordClone(element);
clone = elems.getPasswordClone(element);
if (element.disabled !== clone.disabled) {
clone.disabled = element.disabled;
}
Expand All @@ -89,7 +90,7 @@
}
}

if (!hasValueOrIsActive(element)) {
if (!clone && !hasValueOrIsActive(element)) {
polyfill.showPlaceholder(element);
}

Expand Down
31 changes: 31 additions & 0 deletions test/unit/watch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,36 @@ describe("watching for placeholder changes", function() {

beforeEach(helpers.initialSetup);


describe("when watching enabled and there is a password input with placeholder on the page", function() {
var element;

beforeEach(function(done) {
spyOn(placekeeper.polyfill, "showPlaceholder").and.callThrough();
helpers.spyOnCanChangeToTypeAndReturn(false);
helpers.spyOnNativeSupportAndReturn(false);
element = helpers.createInputElement(true, "password");
placekeeper.priv.__init();
setTimeout(done, helpers.loopDurationForTests);
});

afterEach(function() {
element.parentNode.removeChild(element);
placekeeper.disable();
});

it("should have called polyfill's showPlaceholder method once", function() {
expect(placekeeper.polyfill.showPlaceholder).toHaveBeenCalled();
expect(placekeeper.polyfill.showPlaceholder.calls.count()).toEqual(1);
});

});

describe("when watching enabled and there is an element with placeholder on the page", function() {
var element;

beforeEach(function(done) {
spyOn(placekeeper.polyfill, "showPlaceholder").and.callThrough();
helpers.spyOnNativeSupportAndReturn(false);
element = helpers.createInputElement(true);
placekeeper.priv.__init();
Expand All @@ -18,6 +44,11 @@ describe("watching for placeholder changes", function() {
placekeeper.disable();
});

it("should have called polyfill's showPlaceholder method once", function() {
expect(placekeeper.polyfill.showPlaceholder).toHaveBeenCalled();
expect(placekeeper.polyfill.showPlaceholder.calls.count()).toEqual(1);
});

it("should have set data-placeholder-value to the element", function() {
expect(element.getAttribute("data-placeholder-value")).toEqual("Test");
});
Expand Down

0 comments on commit 4b1759b

Please sign in to comment.