Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE<=9 blur.placeholder #109

Open
redcom opened this issue Dec 27, 2012 · 6 comments
Open

IE<=9 blur.placeholder #109

redcom opened this issue Dec 27, 2012 · 6 comments

Comments

@redcom
Copy link

redcom commented Dec 27, 2012

Placeholder attribute becomes the value of the element when triggering "blur.placeholder"

<input type="text" name="name" placeholder="e.g. John Doe" onkeyup='firePlaceholderKeyup()'>
function firePlaceholderKeyup() {
    $(this).trigger('blur.placeholder');
}

This is the case for IE<-9 where the placeholder value ends up in the value attribute of the element. The text from the palceholder remains in the attribute value if the class is removed and all the action performed with the value attribute contain the text from placeholder.

Possible solution is:
to add the following code to the else branch of setPlaceholder method, just before the

$input.remove(className);

$input[0].value = ($input[0].value !== $input.attr('placeholder'))? $input[0].value: '';
@jli3238
Copy link

jli3238 commented Jan 23, 2013

The following fix works:

Add:

|| input.value == $input.attr('placeholder')

So setPlaceholder() looks like this:

function setPlaceholder() {
var $replacement,
input = this,
$input = $(input),
$origInput = $input,
id = this.id;
if (input.value == '' || input.value == $input.attr('placeholder')) {

@mrhmouse
Copy link

I can confirm this issue. Here is a test page demonstrating how calling blur on an element after calling placeholder will cause the placeholder value to become the input's value.

mrhmouse added a commit to mrhmouse/jquery-placeholder that referenced this issue Jun 13, 2013
@mathiasbynens
Copy link
Owner

Why are you calling blur on it?

@mrhmouse
Copy link

mrhmouse commented Aug 5, 2013

I'm calling blur to remove focus from the input. The plugin functions correctly (in my experience) when a user blurs an input manually via the Tab key or by clicking elsewhere. It also appears to function correctly when focusing another input via focus (as shown here).

@FrittenKeeZ
Copy link

I can confirm that the fix jli3238 posted works.
I call blur on an input field when enter is pressed to perform a search, but in IE8 it will display the placeholder text as the input value.

@PepeuCps
Copy link

I can confirm that the fix jli3238 posted works too.

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

No branches or pull requests

6 participants