javascriptiosmobile-safarimobile-chrome

How to focus <input> with readOnly attribute in iOS?


I try to use readOnly attribute for preventing autofill for an input. I add handler for focus event what remove readOnly attribute and handler for blur event what add readOnly attribute.

But it does not working in any browser in iOS. I found a possible solution to this problem in this answer. But this solution does not work when i try focus one <input> after another. For example, when i try focus <input> after <button> all works fine.

Any idea how to fix it?

Live example: https://codesandbox.io/s/readonly-for-prevent-autofill-76ecn enter image description here


Solution

  •  <input ontouchstart="this.removeAttribute('readonly');" onfocus="this.removeAttribute('readonly');" readonly>

    hmmm ... 5 hours