Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
nrjg
Posts: 44
Registered: ‎09-14-2012
My Device: BB 10 Dev alpha
My Carrier: -
Accepted Solution

TextField focus

[ Edited ]

Is there way to set focus to TextField control?

 

Please use plain text.
Developer
georg22
Posts: 247
Registered: ‎11-22-2011
My Device: Blackberry Playbook
My Carrier: vodafone

Re: TextField focus

I have the same question.

 

How can i set the focus to a textfield control? 

 

For example in the calendar app: When i tap on "Search" the search page opens and the search-TextField has focus and the keyboard appears automatically. How is that done?

Please use plain text.
Developer
georg22
Posts: 247
Registered: ‎11-22-2011
My Device: Blackberry Playbook
My Carrier: vodafone

Re: TextField focus

No idea?

Can someone comfirm, that this is currently not possible?

 

Thanks.

Please use plain text.
Developer
kanaksony
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: TextField focus

Hi,

 

I am having a Search functionality in my app. 

 

QML is - 

TextField {
	       objectName: "searchField"
	       id: searchField
	       clearButtonVisible: true
	       hintText: "Search for Directory"
		       onTextChanging: {
	                        console.log("------Search Bar Text Changing-----------");
	                        directory.searchDirectory();
                       }
}

 

CPP code looks like

void DirectoryList::searchDirectory()
{
	TextField *searchField = page->findChild<TextField*>("searchField");
	QString searchText = searchField->text().trimmed();
	if(searchText!=NULL && searchText.length()>0)
		loadData(searchText);
}

When I tap on TextField, it has Keyboard Up and it seeems focusable. Is it anything else you are asking for, If I am wrong?

 

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Please use plain text.
Developer
georg22
Posts: 247
Registered: ‎11-22-2011
My Device: Blackberry Playbook
My Carrier: vodafone

Re: TextField focus

[ Edited ]

Thanks kanaksony.

No thats not what i am asking for. The Textfield gets automatically the focus by tapping on it or when you swipe the keyboard into the screen. Works fine so far. 

But when you look at the contacts app this happens simply by opening the search page.

The user does not need to tap on the textfield to raise the keyboard or swipe the keyboard into the screen.  

So there must be a way to set the focus on a specific textfield programmatically. 

It is easy iwith the AIR SDK and i allway used it...

Please use plain text.
Developer
d3v3l0p3r
Posts: 168
Registered: ‎07-19-2012
My Device: Q5, Q10, Z10, Z30, PlayBook
My Carrier: Carrier

Re: TextField focus

[ Edited ]

I'm searching for the same ---- want to be abe to open keyboard from JavaScript in QML and set focus to a different (specific) textbox without requiring user to tap on that textbox.

 

 

EDIT:  I found a solution for opening keyboard - although it is not entirely done in QML.

 

Simply created c++ class with Q_INVOKABLE method called showVirtualKeyboard().

 

Inside that method I am calling the

virtualkeyboard_show();

 function which requires the 

bps/virtualkeyboard.h

 header to be included.

 

Exposed this class to QML using 

 

qml->setContextProperty("keyboardControl", myClass);

 and then from QML function called:

keyboardControl.showVirtualKeyboard();

 works fine.

 

Now I can set the focus of specific textbox in QML by calling:

myTextField.requestFocus();

 Works great in beta 3!

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.
Contributor
nrjg
Posts: 44
Registered: ‎09-14-2012
My Device: BB 10 Dev alpha
My Carrier: -

Re: TextField focus

Thanks, it realy works!

 

Summarizing solution is:

1. Show Virtual Keyboard by virtualkeyboard_show (from bps/virtualkeyboard.h)

2. Request focus by requestFocus (defined in Control)

Please use plain text.
Developer
bcs925
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: TextField focus

@d3v3l0p3r Do you have a simple example (or full cpp, hpp, and qml) sample code to show where all these pieces go? I need to do exactly this but I am getting lost somewhere with the different pieces. Thanks.
---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Please use plain text.
BlackBerry Employee
mwatsonbb10
Posts: 2
Registered: ‎06-14-2013
My Device: Z10
My Carrier: Bell

Re: TextField focus

I got it working with pages that are loaded using component definition….works great…below is the implementation example from the docs.  Basically any pages being loaded via Component Definition can send a "ready for focus" signal to the qml page they are pushing.  The qml page defines a bool property that is set to false, but it will be updated to true when it gets the ready for focus signal. So the requestFocus logic is executed only when the bool is true.

 

One thing to remember...a component must be in the UI tree before it can request focus. That is why adding requestFocus to onCreationCompleted methods will not work.

 

 

This solution involves using a ComponentDefinition to load the pages. Here's another version called RequestFocusPage2.qml. It contains a Boolean property called readyForFocus which is initialized to false. When the value changes, the onreadyForFocusChanged() signal handler is called and focus is requested.

import bb.cascades 1.0

 

Page {

    property bool readyForFocus: false

    Container {

        TextArea {

            id: theTextArea

            text: "I want some focus too!"

        }

    }

    onReadyForFocusChanged: {

        if (readyForFocus) {

            // This triggers focus if the Page is created using a

            // ComponentDefinition.

            theTextArea.requestFocus();

        }

    }

}

Here's how you can create the Page and set the readyForFocus property from a ComponentDefinition in a NavigationPane:

import bb.cascades 1.0

 

NavigationPane {

    id: nav

    RequestFocusPage {

        actions: ActionItem {

            ActionBar.placement: ActionBarPlacement.OnBar

            title: "Navigate"

            onTriggered: {

                var page = refocusPage.createObject();

                nav.push(page);

 

                // Here it is ok to trigger the focus request since the page is added to

                // the UI tree as it is pushed to the NavigationPane.

                page.readyForFocus = true;

            }

        }

    }

    attachedObjects: ComponentDefinition {

        id: refocusPage

        source: "RequestFocusPage2.qml"

    }

    onPopTransitionEnded: {

        page.destroy()

    }

}

Please use plain text.
BlackBerry Employee
mwatsonbb10
Posts: 2
Registered: ‎06-14-2013
My Device: Z10
My Carrier: Bell

Re: TextField focus

...and i forgot...it brings up the virtual keyboard automatically when it gets the focus. (tested and verified).

Please use plain text.