Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Explorer 10 and 11 remove placeholder text when the input is focused

When using Internet Explorer 10 and 11, input placeholder text is removed if the input is focused using the autofocus attribute. For example:

<input type="textbox" value="" placeholder="Example text" autofocus>

Demo: https://jsfiddle.net/ompkwtz5/

How can I ensure the placeholder text isn't removed?

Ref: https://connect.microsoft.com/IE/feedback/details/885747/ie-11-fires-the-input-event-when-a-input-field-with-placeholder-is-focused

like image 433
henrywright Avatar asked May 06 '15 02:05

henrywright


People also ask

How do I change the placeholder text?

The “placeholder” property is used to get or set the placeholder of an input text. This can be used to change the placeholder text to a new one. The element is first selected using a jQuery selector. The new placeholder text can then be assigned to the element's placeholder property.


2 Answers

It's an IE bug, the one in your reference link.

Take a look at jquery-placeholder. Will also support IE6! I'm not sure if it will work out of the box though, because IE10 is supposed to support the placeholder attribute, so check if jQuery.fn.placeholder.input is true (more info in the README). If it is, the plugin won't do anything, so you might need to override its checking behaviour.

Amazing that the bug is still active.

like image 29
p4sh4 Avatar answered Sep 22 '22 19:09

p4sh4


Found a solution only with css. https://jsfiddle.net/nikdko/grc6v03a/

PS:withs input:valid + .fakePlaceholder {display:none } ie gets freeze

<input type="text" pattern=".+" required="" />
<span class = "fakePlaceholder">Fake placeholder />

input {
    position: relative;
    top: 0;
    border: 1px solid #999;
    z-index: 1;
}
.fakePlaceholder{
    color: #7D838A;
    position: absolute;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 100%;
    pointer-events: none;
    left: 0;
    z-index: 1;
    padding-left: 10px;
}
input:valid {
    background-color: #FFFFFF;
    z-index: 2;
}
like image 168
Никита Романец Avatar answered Sep 23 '22 19:09

Никита Романец