This is a migrated thread and some comments may be shown as answers.

Focus and softkeyboard

4 Answers 181 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
javier
Top achievements
Rank 1
javier asked on 19 Jan 2017, 09:10 AM
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

4 Answers, 1 is accepted

Sort by
0
Nikolay Tsonev
Telerik team
answered on 19 Jan 2017, 04:08 PM
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  In this event, check for the name of the property, which you would like to focus.

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

For your 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.
0
javier
Top achievements
Rank 1
answered on 20 Jan 2017, 08:13 AM

The requestFocus methos is working, thanks.

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

Regards

0
Accepted
Nikolay Tsonev
Telerik team
answered on 20 Jan 2017, 03:12 PM
Hello,

It is possible to show the keyboard, by accessing android This will allow you to show the keyboard just after the Entity has been focused. For your 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.
0
javier
Top achievements
Rank 1
answered on 23 Jan 2017, 05:54 PM

Hello,

It work fine too.

Thank you for your answer.

 

Tags
DataForm
Asked by
javier
Top achievements
Rank 1
Answers by
Nikolay Tsonev
Telerik team
javier
Top achievements
Rank 1
Share this question
or