3

EDIT: this feat is impossible. since then I have given up. I shall not delete this question, but rather leave it up right here so future users can see a relevant result to their query on google regarding a similar thing

  • Goal: Either make a textarea bring up the virtual keyboard when focused(with js) OR make a input[type=text] have multiple lines AND bring the virtual keyboard (I believe answered here but with unsatisfactory results.) (If anyone knows of fully compatible ways to multiple-line-ify an input[type=text] please tell me)

  • Expected results: virtual keyboard popup when focusing the input OR textarea fields (via javascript with no user trigger).

  • Real results: caret appears in text field but keyboard remains unseen.

  • Here's what I'm trying on a textarea:

document.elementFromPoint(document.querySelector("textarea").getBoundingClientRect().x, document.querySelector("textarea").getBoundingClientRect().y).dispatchEvent(click);
  • Please don't make irrelevant comments about my code organization
  • @WaisKamal can you show me your code since you said it works?
  • HTML(no CSS):
<textarea>textarea</textarea>
<input type="text" value="input" />
<script>
//document.elementFromPoint(document.querySelector("textarea").getBoundingClientRect().x, document.querySelector("textarea").getBoundingClientRect().y).dispatchEvent("click");
document.querySelector("input").focus();
document.querySelector("input").click();
</script>
somebody
  • 97
  • 10

1 Answers1

1

You can use inputmode to determine how a virtual keyboard behaves

<textarea>textarea</textarea>
<input type="text" value="input" inputmode='text'/>
<script>
//document.elementFromPoint(document.querySelector("textarea").getBoundingClientRect().x, document.querySelector("textarea").getBoundingClientRect().y).dispatchEvent("click");
document.querySelector("input").focus();
document.querySelector("input").click();
</script>

Edit

I'm still testing this out, it seem to give some mixed results in the jsfiddle that I'm currently testing right now, sometimes it works and sometimes it does not

*Edit 2 *

It seems to have the same results without specifying the inputmode It does not work the first time the page loads but if I click somewhere on the page, it works every time I click run.

I'm only speculating here but it seems like the keyboard does not pop up without the page receiving some user interaction first, maybe this is intentional for security reasons but I didn't find any docs saying so.

As for you other question you can give a div or other container element contenteditable to have multiple rows / any dimensions you want.

-

Here is another questions and some answers to the same problem though a bit old, Show virtual keyboard on mobile phones in javascript

-

All in all it does not seem possible so show a virtual keyboard without some user interaction.

RDU
  • 812
  • 1
  • 9
  • 22