New feature: add support for stay on focus #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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