0
votes

When user click ouside of TextField , I want to remove focus from textfield. How to do this in nativescript ?

1
To be more precise, you want to hide the keyboard or remove the focus too? In Android focus can be still on TextField while keyboard is hidden. With iOS, hiding the keyboard will also remove focus. - Manoj
I want to hide keyboard as well as remove the focus. - Rushikesh Shirkar

1 Answers

1
votes

Here is how you could remove focus from your TextField on Android. You need another view where the focus can be shifted. The sample was done with {N} core, implementing in {N} Vue follows the standard steps, register the custom element and use it on your template.

To hide keyboard, execute the code below upon tapping your layout (anywhere outside the TextField).

import * as utils from "tns-core-modules/utils/utils";

if (utils.ad) {
  utils.ad.dismissSoftInput();
} else {
  // iOS
  utils.ios
            .getter(UIApplication, UIApplication.sharedApplication)
            .keyWindow
            .endEditing(true);
}