Skip to content

Conversation

@etiktin
Copy link

@etiktin etiktin commented Nov 1, 2014

The native placeholder behavior of current versions of Chrome and Firefox is to stay on focus until the user enters a value. This makes sense because a lot of developers are using placeholders in order to
instruct the user what to enter in the field. So while the field is in focus, but no value was entered, the instructions should still be displayed.
The way that the placeholder plugin currently works, the placeholder is hidden on focus.

I wanted to have the new behavior so I added support for it.

To use it you need to initialize placeholder with the "stayOnFocus" option set to true. Here's an example call:
$('input[placeholder], textarea[placeholder]').placeholder({force: true, stayOnFocus: true});
If you don't pass the new option (or you pass stayOnFocus=false) the behavior will remain as it was before (placeholder is hidden on focus). You can call it with or without force=true depending on if you want to replace the native browser behavior. For my project I set both force and stayOnFocus to true, because I wanted consistent behavior a cross all browsers.

To see an example of the old behavior, take a look at:
http://codepen.io/anon/pen/lnkhd
To see the new behavior (stayOnFocus=true), take a look at:
http://codepen.io/anon/pen/cDAjl

The native placeholder behavior of current versions of Chrome and
Firefox is to stay on focus until the user enters a value. This makes
sense because a lot of developers are using placeholders in order to
instruct the user what to enter in the field. So while the field is in
focus, but no value was entered, the instructions should still be
displayed.
The way that the placeholder plugin currently works, the placeholder is
hidden on focus.

I wanted to have the new behavior so I added support for it.

To use it you need to initialize placeholder with the "stayOnFocus"
option set to true. Here's an example call:
$('input[placeholder], textarea[placeholder]').placeholder({force: true,
stayOnFocus: true});
If you don't pass the new option the behavior will remain as it was
before (placeholder is hidden on focus).

To see an example of the old behavior, take a look at:
http://codepen.io/anon/pen/lnkhd
To see the new behavior (stayOnFocus=true), take a look at:
http://codepen.io/anon/pen/cDAjl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant