'keep keyboard open on Ionic when button click ( chat app )
I have an Ionic v1 chat application, I made everything, but I encountred the famous problem when clicking on a send button (send chat) the keyboard loses focus from the input and then closes.
I've tried many approaches, but it none of them work:
- Input directive to keep focus,
- forcing focus on click event,
- modifying the value of InputUserAction in config.xml to false.
Any help is much appreciated.
<div class="sender">
<input type="text" ng-model="..." class="...">
<div class="button-send">
<span class="send-chat"><i class="ion ion-send"></i></span>
</div>
</div>
Solution 1:[1]
just use (mousedown)="sentMessage(); $event.preventDefault()"
<ion-button (mousedown)="sentMessage(); $event.preventDefault()">
<ion-icon ios="ios-send" md="md-send"></ion-icon>
</ion-button>
Solution 2:[2]
ALright found a fix! for all of you out there, who are using ionic for a chat like app, and want the keyboard to stay focused after clicking on a button,
Just, replace the button by a label with for="inputID" like so:
<div class="sender">
<input id="inputID" type="text" ng-model="..." class="...">
<div class="button-send">
<label for="inputID" class="send-chat"><i class="ion ion-send"></i></label>
</div>
</div>
Solution 3:[3]
(mousedown)="doSomething(); $event.preventDefault()"
works with latest Ionic version too.
Solution 4:[4]
Try forcing the keyboard to open via it's cordova plugin https://github.com/ionic-team/ionic-plugin-keyboard#keyboardshow
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | shanthan |
Solution 2 | Sletheren |
Solution 3 | Suraj Rao |
Solution 4 | Marouan |