Tekerson Tekerson - 3 months ago 15
HTML Question

Submit form without loosing soft keyboard

I have been trying to find a similar post to this question within the forum with no success. I have a simple form composed by a textarea and a button to submit on a app using angularJS. It works fine. However, when I press submit I loose the focus of the textarea so the keyboard disappears, and when I press on the textarea shows off again. I would like to keep it visible even if I press submit.

Answer

You can try attaching a handler to focusout event and focus the textarea inside that handler.

If you want to focus back to textarea only when the button is clicked, you can attach the handler to your button's click event instead.

//This will prevent textarea from being focused out
//$("textarea").on("focus", function(e) {
//  $(this).focus();
//});

$("button").on("click", function(e) {
  $("textarea").focus();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<textarea></textarea>
<button>Submit</button>