I'm making an app with the Ubuntu SDK where a user has to enter a number as fast as possible. I have a textfield in a page, where he has to enter the number:
TextField {
id: inputQuestion
width: 100
height: 50
errorHighlight: true
validator: IntValidator { }
text: '?'
}
I have two questions about that:
- How can I make it so the TextField is automatically selected when the page opens? (the cursor is in the textbox)
- How can I make it so the numpad of the smartphone/tablet automatically opens when the page opens?
It is quite simple to do the above. To set automatic focus to the TextField component, you can call forceActiveFocus() from within your TextField component as shown below,
This sets the focus to the textfield immediately after it is loaded.
As for showing the numpad, you can do so by setting the input hint to numbers only,
Your TextField should look like,
Note: Do not set the width and height in pixels. Use grid units as shown in the example above since that will ensure that the textfield has the same dimensions on all devices regardless of their pixel density.