Skip to content

Commit

Permalink
Merge pull request mathiasbynens#57 from sbull/empty-string-val-issue-56
Browse files Browse the repository at this point in the history
Don’t `setPlaceholder` if the element has focus

Fixes mathiasbynens#56.
  • Loading branch information
mathiasbynens committed Feb 23, 2012
2 parents 5148335 + cb53e48 commit a9fd43d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions jquery.placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
}
if (value == '') {
element.value = value;
// We can’t use `triggerHandler` here because of dummy text/password inputs :(
setPlaceholder.call(element);
// Issue #56: Setting the placeholder causes problems if the element continues to have focus.
if (!$element.is(':focus')) {
// We can’t use `triggerHandler` here because of dummy text/password inputs :(
setPlaceholder.call(element);
}
} else if ($element.hasClass('placeholder')) {
clearPlaceholder.call(element, true, value) || (element.value = value);
} else {
Expand Down

0 comments on commit a9fd43d

Please sign in to comment.