How to prevent a cord to hide the keyboard when the input loses focus

I am making a phone chat application for Android, but I have a problem.

I have a text area field (where users can write their messages) and a button for sending messages.

When a user clicks on a text area, a keyboard appears. However, when the user presses a button to send a message, the text area field loses focus and the keyboard disappears. I would like to keep the keyboard displayed and return focus to the text area.

I tried to select a keyboard using

$('#text-area).focus() 

But that did not work.

I also added this line to my config.xml file.

 <preference name="KeyboardDisplayRequiresUserAction" value="false"/> 

I tried using the plugin https://github.com/driftyco/ionic-plugins-keyboard . When the keyboard is hiding, it fires an event, but the only thing I can do is open it again with

 cordova.plugins.Keyboard.show(); 

The problem is that hide / show keyboard and animation still run.

Any tips?

+6
source share
2 answers

I had a similar problem. You need to use the focus directive for this, just use this link, I think you understand the meaning and some help:

Set the focus of an angular element

0
source

I did it like this:

 <textarea id="NewTextBox" ng-model="newMsgModel.text" ng-click="add()"></textarea> 

and in angular JS:

 $scope.add = function () { /** add message to db ...*/ /** keep Keyboard Open*/ $('#NewTextBox').focus(); }; 
0
source

Source: https://habr.com/ru/post/1211186/


All Articles