Focus and softkeyboard

Thread is closed for posting
5 posts, 1 answers
  1. javier
    javier avatar
    3 posts
    Member since:
    Jan 2017

    Posted 19 Jan 2017 Link to this post

    Hello,

    In android, It is posible to set focus on a EntityProperty programmatically ?

    It is posible control the show and hidde of android soft keyboard programmatically ?

    I need set focus and open soft keyboard on page load under certains conditions, and when the user press the softkeyboard next button reopen the softkeyboard in the new EntityProperty that become focus.


    Regards
  2. Nikolay Tsonev
    Admin
    Nikolay Tsonev avatar
    340 posts

    Posted 19 Jan 2017 Link to this post

    Hi,

    Thank you for your question.

    While using RadDataForm you could use `requestFocus()` android method, which will allow you to change the focus on a specific EntityProperty.

    In case you would like to focus on a specific Entity just after DataForm has been loaded, you could use editorUpdateEvent . In this event, you  should check for the name of the property, which you would like to focus.

    On other hand if you would like to change the focus on tap event, you could use getPropertyByName  method, which will return the needed EntityProperty and to access its native object, while using its android property.

    For your convenience I am providing sample code for the both cases.

    XML
    <GridLayout rows="auto, *" orientation="vertical">
        <Label margin="12" id="myLabel" tap="focusField" text="Change focus" row="0"/>
        <df:RadDataForm id="myDataForm" editorUpdate="dfEditorUpdate" source="{{ person }}" marginTop="50" row="1"
            groupExpanded="dfGroupExpanded"
            groupCollapsed="dfGroupCollapsed"
            propertyCommit="dfPropertyCommit"
            propertyCommitted="dfPropertyCommitted">
            <df:RadDataForm.groups>
                <df:PropertyGroup collapsible="true" name="Main Info" >
                    <df:PropertyGroup.properties>
                        <df:EntityProperty name="name" />
                        <df:EntityProperty name="age" />
                        <df:EntityProperty name="email" />
                    </df:PropertyGroup.properties>
                </df:PropertyGroup>
                <df:PropertyGroup collapsible="true" name="Address" >
                    <df:PropertyGroup.properties>
                        <df:EntityProperty name="city" />
                        <df:EntityProperty name="street" />
                        <df:EntityProperty name="streetNumber" />
                    </df:PropertyGroup.properties>
                </df:PropertyGroup>
            </df:RadDataForm.groups>
        </df:RadDataForm>
        </GridLayout>


    TypeScript

    import viewModel = require("./../view-models/person-model");
    import viewModule = require("ui/core/view");
    import dialogs = require("ui/dialogs");
    import {RadDataForm, EntityProperty} from "nativescript-telerik-ui-pro/dataform";
    import {isAndroid} from "platform"
     
    var label;
    var page;
    export function onPageLoaded(args) {
        page = args.object;
        page.bindingContext = new viewModel.PersonViewModel();
     
      
    }
     
    export function dfPropertyCommit(args) {
        if (args.propertyName == "name") {
            label.text = "LastEvent: name property commit cancelled";
            args.returnValue = false;
        }
    }
     
    export function dfPropertyCommitted(args) {
        label.text = "LastEvent: " + args.propertyName + " property committed";
    }
     
    export function dfGroupExpanded(args) {
        label.text = "LastEvent: " + args.groupName + " group expanded";
    }
     
    export function dfGroupCollapsed(args) {
        label.text = "LastEvent: " + args.groupName + " group collapsed";
    }
     
     
    export function dfEditorUpdate(data) {
        if(data.propertyName == "street" && isAndroid) {
            data.editor.getEditorView().requestFocus();
            console.log(data.editor.getEditorView());
        }
    }
     
    export function focusField(){
        if(isAndroid){
            var dataform:RadDataForm=<RadDataForm>page.getViewById("myDataForm");
            var property:EntityProperty = <EntityProperty>dataform.getPropertyByName("name");
            property.editor.android.getEditorView().requestFocus();
        }
         
    }



    Hope this helps.

    Regards,
    nikolay.tsonev
    Telerik by Progress
    Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
  3. javier
    javier avatar
    3 posts
    Member since:
    Jan 2017

    Posted 20 Jan 2017 in reply to Nikolay Tsonev Link to this post

    The requestFocus methos is working, thanks.

    I need an answer about how to open softkeyboard programatically when an item is focusing.

    Regards

  4. Answer
    Nikolay Tsonev
    Admin
    Nikolay Tsonev avatar
    340 posts

    Posted 20 Jan 2017 Link to this post

    Hello,

    It is possible to show the keyboard, by accessing android InputMethodManager  . This will allow you to show the keyboard just after the Entity has been focused. For your help I am attaching sample code.

    TypeScript

    import app = require("application");
    declare var InputMethodManager:any;
     
    .........
     
    export function focusField(){
        if(isAndroid){
            var dataform:RadDataForm=<RadDataForm>page.getViewById("myDataForm");
            var property:EntityProperty = <EntityProperty>dataform.getPropertyByName("name");
     
            if(property.editor.android.getEditorView().requestFocus()){
                var edittext = property.editor.android.getEditorView();
                var context = app.android.context;
                var inputMethodManager = context.getSystemService("input_method");
                inputMethodManager.showSoftInput(edittext, 0);
            };
        }
         
    }


    Let me know, whether this helps or if I could assist you further.

    Regards,
    nikolay.tsonev
    Telerik by Progress
    Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
  5. javier
    javier avatar
    3 posts
    Member since:
    Jan 2017

    Posted 23 Jan 2017 in reply to Nikolay Tsonev Link to this post

    Hello,

    It work fine too.

    Thank you for your answer.

     

Back to Top