question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

focusFirstInput (Modal) doesn't work on Android

See original GitHub issue

I was able to make it working on iOS adding <preference name="KeyboardDisplayRequiresUserAction" value="false" /> in the config.xml.

I don’t how to do on Android, I’ve tried to use this cordova plugin (https://github.com/phonostar/PhoneGap-SoftKeyboard.git) but it doesn’t work. Suggestions?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
hypery2kcommented, Jan 5, 2015

together with the IonicKeyboard Plugin I found a working solution on iOS 7+ and Android 4.4+ by using a directive

/**
 * @ngdoc directive
 * @name isFocused
 * @module flynnBookScannerApp
 * @description gives focus the the element, can be used as attribute
 */
app.directive('isFocused', function($timeout) {
    return {
        scope: {
            trigger: '&isFocused'
        },
        link: function(scope, element) {
            if (scope.trigger()) {
                $timeout(function() {
                    element[0].focus();
                    element[0].click();
                    cordova.plugins.Keyboard.show();
                });
            }
        }
    };
});

in HTML

<input type="search" data-ng-model="searchQuery.fullTextSearch"  is-focused="true"
                   placeholder="Type keywords to search ...">

and this config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" 
...
    <preference name="fullscreen" value="false" />
    <preference name="webviewbounce" value="false" />
    <preference name="UIWebViewBounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />
    <preference name="KeyboardDisplayRequiresUserAction" value="false" />
</widget>

See the full example here:

We’re using beta4 in the app

1reaction
frissonlabscommented, Jun 28, 2014

In order to get the keyboard to display on focus, you can use the following directive:

angular.module('directives')
.directive('isFocused', function($timeout) {
  return {
    scope: { trigger: '&isFocused' },
    link: function(scope, element) {
        if(scope.trigger()) {
          $timeout(function() {
            element[0].focus();
            element[0].click();
          });
        }
    }
  };
});

for example:

<textarea rows="8" ng-model="text" is-focused="true"></textarea>

I’m guessing the default implementation does not include the auto-display of the keyboard on focus for fear of hiding content unintentionally.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TextInput Doesn't Get Focus Inside a Modal - React Native ...
I have 4 TextInputs in a Modal, the first TextInput get the focus without any problem, but the rest don't get focus.
Read more >
[Android - Modal ] TextInput doesn't get focus · Issue #7031
The problem is that the top TouchableOpacity fires on the first click, even when the field is focused, but the bottom one requires...
Read more >
focus - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
The :focus CSS pseudo-class represents an element (such as a form input) that has received focus. It is generally triggered when the user ......
Read more >
Control focus with tabindex - web.dev
Try pressing the Tab key to navigate through your site. Are you able to reach all the interactive controls on the page? If...
Read more >
How to Set Focus on Input Field or Textarea Inside a Bootstrap ...
Answer: Use the jQuery .focus() method. You can simply use the jQuery .focus() method to set the focus on the first input box...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found