Keyboard hiding even with event.preventdefault

I have a chat application and I would like the user to click a send button on the UI and the keyboard stay open. Normally the keyboard closes, I am guessing because the input element loses focus when the button is click. At the moment the keyboard comes straight back because of the timeout code, however this is noticeable from the user and I would prefer the keyboard to stay.

This is on iOS, seen in multiple versions 8 and 9. I’m using ionic version 1.0.0 and com.ionic.keyboard version 1.0.4

Does anyone know how to keep the keyboard open during this bit of javascript? Only the first and second line actually need to run.

$scope.sendChat = function($event) {
      backend.addMessage($scope.data.chatInput);
      $scope.data.chatInput = '';
      $event.preventDefault();
      $event.stopPropagation();
      $timeout(function() {
        if ($scope.inputEl) {
          $scope.inputEl.focus();          
        }
      }, 0);
};
1 Like