6

I'm making a chat application for android with phonegap but i'm facing a problem.

I have a text area field (where the users can write their messages) and a button to send the messages.

When the user clicks on the text area, the keyboard comes up. However, when the user clicks the button to send the message, the text area field loses the focus and the keyboard disappears. I'd like to keep to keyboard displayed and give back the focus to the text area.

I've tried to select the keyboard with

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

But it didn't work out.

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

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

I've tried to use the plugin https://github.com/driftyco/ionic-plugins-keyboard. When the keyboard is going to hide, it fires an event but the only thing I can do is to open it again with

cordova.plugins.Keyboard.show();

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

Any advices ?

2 Answers2

1

I had the similar issue. You need to use focus directive for that just use this link i think you get the point and some help :

Set element focus in angular way

Community
  • 1
  • 1
Parvindra Singh
  • 53
  • 2
  • 10
0

i have done this like this:

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

and in angularJS:

$scope.add = function () {
    /** add message to db ...*/ 

    /** keep Keyboard Open*/
    $('#NewTextBox').focus();
};
user4649102
  • 463
  • 6
  • 13
  • Shouldn't the answer involve putting an `ng-click` handler on a button instead of the `textarea`? (Re-read OP's question) – rinogo Oct 27 '16 at 23:07