最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - New input placeholder behavior in Safari 10 - no longer hides on change via JavaScript - Stack Overflow

programmeradmin0浏览0评论

Safari 10.0 in macOS Sierra seems to have changed the way the placeholder in an input behaves when the input value is changed via JavaScript. It now also differs from what Chrome (53.0.2785.116) is doing.

Until now, when setting an input value via JavaScript the placeholder would disappear. After setting the value back to empty via JavaScript, the placeholder would reappear.

Now, setting the input value via JavaScript does not hide the placeholder, until the input gains focus afterwards (e.g. by being clicked on).

Check this JS Bin for a demo: ,js,output

Is this the intended behavior? If so, is there a clever workaround for hiding/unhiding the placeholder after a change via JavaScript?

Edit: This has now been filed at rdar://28412751 for Safari 10 and the Safari Technology Preview.

Safari 10.0 in macOS Sierra seems to have changed the way the placeholder in an input behaves when the input value is changed via JavaScript. It now also differs from what Chrome (53.0.2785.116) is doing.

Until now, when setting an input value via JavaScript the placeholder would disappear. After setting the value back to empty via JavaScript, the placeholder would reappear.

Now, setting the input value via JavaScript does not hide the placeholder, until the input gains focus afterwards (e.g. by being clicked on).

Check this JS Bin for a demo: https://jsbin.com/rogoludahu/edit?html,js,output

Is this the intended behavior? If so, is there a clever workaround for hiding/unhiding the placeholder after a change via JavaScript?

Edit: This has now been filed at rdar://28412751 for Safari 10 and the Safari Technology Preview.

Share Improve this question edited Sep 28, 2016 at 18:37 Joshua asked Sep 21, 2016 at 19:20 JoshuaJoshua 1,72319 silver badges27 bronze badges 7
  • 2 I noticed the same behaviour! To me, this seems to be a bug – Andrea Marcolin Commented Sep 27, 2016 at 9:09
  • 4 Most likely a bug. Rather hacky way to fix is to set the value twice as a temporary solution jsbin.com/qiloyuxura/1/edit?html,js,output – Tigran Petrossian Commented Oct 14, 2016 at 6:26
  • try this maybe: document.getElementById("myInput").setAttribute('value', "New Value"); – Dalin Huang Commented Mar 23, 2017 at 20:57
  • @DalinHuang: Nice idea, but no change for me - feel free to try in the JS Bin. – Joshua Commented Mar 26, 2017 at 9:11
  • 1 Where is rdar://28412751? – chipit24 Commented Jun 29, 2017 at 18:09
 |  Show 2 more comments

4 Answers 4

Reset to default 5

I ran into this problem earlier today. As far as I've seen, there is no good solution. My hacky workaround was to call .focus() and then .blur() on the element as soon as the value was given to it.

This has been resolved in Safari Technology Preview Release 37 (Safari 11.1, WebKit 12605.1.2) as well as in regular Safari Version 11.0.3 (WebKit 13604.5.6).

According to this Apple thread (and confirmed by one of my coworkers), this is only an issue if you've opened the Javascript console. So, you probably don't need to worry about a workaround!

I don't know if the bug returned or was never fixed properly (Safari 11.0.3). Can be reproducible with the jsbin from Joshua. The solution for us was to redraw the field on change. We are using ExtJS so this is a snipped for the field override, but should be able to apply it in any other framework or vanila.

if(Ext.isSafari && !Ext.isEmpty(me.emptyText)) {
    me.on('change', function() {
        var me = this;

        if(me.rendered && me.el && Ext.isFunction(me.el.redraw)) {
            me.el.redraw()
        }
    })  
}
发布评论

评论列表(0)

  1. 暂无评论