Focus in Focus

This is the place to discuss anything relating to MobGUI

Moderators: heatherlaine, kevinmiller, robinmiller, malte, splash21

Post Reply
dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 114
Joined: Wed Apr 08, 2009 11:54 pm
Location: Shellharbour, Australia

Focus in Focus

Post by dickey » Mon Jan 09, 2012 1:34 am

Hello Forum,

What is the preferred way to focus on MobGUI native iOS controls, like the Text Field?

Thank you in advance.

Kind regards, Andrew

pthirkell
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 93
Joined: Tue Nov 17, 2009 6:47 pm
Location: Wellington, New Zealand

Re: Focus in Focus

Post by pthirkell » Mon Jan 09, 2012 10:41 am

Maybe I'm missing the point here ... but just tap on the field? That brings focus and automatically reveals the keyboard.

dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 114
Joined: Wed Apr 08, 2009 11:54 pm
Location: Shellharbour, Australia

Re: Focus in Focus

Post by dickey » Mon Jan 09, 2012 11:17 am

Hello pthirkell,

Perhaps I should have said:

What is the preferred way to programmatically focus on MobGUI native iOS controls, like the Text Field?

I want the focus to be on a particular MobGui generated native iOS field when the card opens, so that the user is not forced to touch the field to attain focus.

I was not sure whether the regular focus command worked, or whether you send a touch to the field (which in fact is a group, and may need to be referenced in a different way), or whether from the release notes you use something like iphoneControlDo id, "focus" etc. Still not sure of the correct way, that's why I asked.

Kind regards, Andrew

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Focus in Focus

Post by Dixie » Mon Jan 09, 2012 12:19 pm

Andrew...

try

Code: Select all

focus on fld "whateverName"
be well

Dixie

dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 114
Joined: Wed Apr 08, 2009 11:54 pm
Location: Shellharbour, Australia

Re: Focus in Focus

Post by dickey » Mon Jan 09, 2012 12:53 pm

Hello Dixie,

Thank you, for your reply. I did try your suggestion earlier - it does not work.

Recipe:
I create a new stack with MobGUI.
I navigate to the Native iOS controls (panel)
I drag on a native text field, and name it 'dixie'
I drag on a standard button, and edit it's script and create a on mouseUp handler:

Code: Select all

on mouseUp
   focus on field "dixie"
end mouseUp
When I run the stack in the IDE, and click on my button which is to give focus to the native text field, it bombs with the error:
button "Button": execution error at line 2 (Chunk: no such object) near "dixie", char 10.

Dixie, I suspected focus would not work in this manner as we are not dealing with LiveCode IDE fields. In the case of the MobGUI's native iOS text field, we are dealing with a group of objects.

Therefore, I suspect such groups of objects are probably referenced in another manner. I guess that is the heart of the question.

Kind regards, Andrew

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: Focus in Focus

Post by Dixie » Mon Jan 09, 2012 3:30 pm

Andrew...

Apologies... Have a look at page 48 od the iOS release notes. You are able to set the 'enabled' property of the UITextField to true or false as in... iphoneControlSet idOrName, property, value

be well

Dixie

dickey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 114
Joined: Wed Apr 08, 2009 11:54 pm
Location: Shellharbour, Australia

Re: Focus in Focus

Post by dickey » Wed Jan 11, 2012 12:22 pm

Thank you for your assistance Dixie,

The solution:
First in response to your comments Dixie:
iosUITextField is enabled by default when dragged onto a card from the MobGUI palette. Therefore there is no requirement to set the iosUITextField to enabled in your code. Should you wish to enable or disable your iosUITextField, you would do so as follows:

Code: Select all

global gInputA
iphoneControlDo gInputA["theNameOfYourIosUITextField"], "enabled", "true"
Back to the focus of the question, which was programmatically providing focus to a iosUITextField.

Simply:

Code: Select all

global gInputA
iphoneControlDo gInputA["theNameOfYourIosUITextField"], "focus"
The reason this did not work for me first time around, is that I experienced some form of corruption with my stack, that prevented the global gInputA from being updated by the creation of each new iosUITextField.

Thanks again, for your comments, and I hope someone else may benefit from this.

Kind regards, Andrew

Post Reply

Return to “MobGUI”