Multiple native input controls...

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
PaulMaguire
Posts: 44
Joined: Wed Feb 13, 2013 3:38 pm
Location: Glasgow, Scotland
Contact:

Multiple native input controls...

Post by PaulMaguire » Mon Apr 29, 2013 3:25 pm

Hi.

I'm trying to implement my first ever native iOS (and Android) input controls - one is single line for email address, other is for a message (multiline). I am creating both controls on a single card:

Code: Select all

inputCreator "emailInput", "input", "F_inputFieldEmail", "TRUE", "none", "no", "email"
inputCreator "commentInput", "multiline", "F_inputFieldComment", "FALSE", "sentences", "yes", "default"
... from a custom creator handler something like this:

Code: Select all

on inputCreator pName, pKind, pFld, pAutoFit, pAutoCap, pAutoCorrect, pKeyboardType
   iphoneControlCreate pKind, pName
   iphoneControlSet pName, "rect", the rect of fld pFld
   iphoneControlSet pName, "opaque", "FALSE"
   iphoneControlSet pName, "backgroundColor", "0,0,0,0"
   iphoneControlSet pName, "autoFit", pAutoFit
   iphoneControlSet pName, "autoClear", "FALSE"
   iphoneControlSet pName, "clearButtonMode", "whileEditing"
   iphoneControlSet pName, "autoCapitalizationType", pAutoCap
   iphoneControlSet pName, "autoCorrectionType", pAutoCorrect
   iphoneControlSet pName, "keyboardType", pKeyboardType
   iphoneControlSet pName, "returnKeyType", "done"
end inputCreator
The code I am using to manage and monitor fields is essential the same as the Livecode tutorial stack on input controls. It reports when text has been edited and when return is hit etc. The problem is I cannot work out how to manage 2 controls on 1 card - "commentInput" uses the Return as a return in the field whereas "emailInput" pops out of edit mode (and hides the native keyboard). I want both returns to come out of editing mode (or at least have the multiline have a 'done' button appear). How do I track which field is in focus? This seems more complex than it should be - must be a common issue. Apologies for simplicity of this query - just not sure of the best practice here...

Kind regards, Paul.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Multiple native input controls...

Post by Jellicle » Mon Apr 29, 2013 11:38 pm

From the release notes for iOS:

"While in the context of a message that has been dispatched from a native control, you can use the iphoneControlTarget() function to fetch the name (or id, if no name is set) of the control that sent the message."

On Android the release notes substitute "mobileControlTarget()" for "iPhoneControlTarget()". That probably works for both platforms.

Does that help?

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

PaulMaguire
Posts: 44
Joined: Wed Feb 13, 2013 3:38 pm
Location: Glasgow, Scotland
Contact:

Re: Multiple native input controls...

Post by PaulMaguire » Tue Apr 30, 2013 9:41 am

Excellent - I'll check it out. Thanks.

PaulMaguire
Posts: 44
Joined: Wed Feb 13, 2013 3:38 pm
Location: Glasgow, Scotland
Contact:

Re: Multiple native input controls...

Post by PaulMaguire » Thu May 02, 2013 1:20 pm

HI again.

Just following this up. MobileControlTarget() is what I was looking for. Thanks again.

But... I still have an issue: My email input control (single line) works as I want it - type in it (opens email-specific native keyboard yay!) and push the 'done' button and focus is lost from the input and the native keyboard disappears. But my multiline field doesn't behave like this - the return button (done) inputs a normal return in the multiline control. I want to trap this return, defocus the multiline input and kill the native keyboard. I can't see any way of doing this - there is no response form the inputReturnKey message when return button is touched in a multiline control. Any idea how to handle this? Must be a common task for all mobile LC developers! I also can't see a way of programatically/manually defocussing an input control ie. hiding the keyboard input...

Any wisdom much appreciated.

Kind regards, Paul.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Multiple native input controls...

Post by Simon » Thu May 02, 2013 8:49 pm

Hi Paul,
You can use a rawKeyDown for this:

Code: Select all

on rawKeyDown theKeyNumber
   if theKeyNumber = 65293 then -- 65293 is the return key
      focus on nothing
   else 
      pass rawKeyDown
   end if
end rawKeyDown
put that into your field and it should give you the results you want.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Multiple native input controls...

Post by Jellicle » Fri May 03, 2013 4:59 am

Try this in your card script:

Code: Select all

on inputReturnKey
  if iphonecontroltarget() = "commentinput" then
      focus on nothing
  end if
end inputReturnKey
That will remove focus from the input control and hide the keyboard.
14" MacBook Pro
Former LiveCode developer.
Now recovering.

PaulMaguire
Posts: 44
Joined: Wed Feb 13, 2013 3:38 pm
Location: Glasgow, Scotland
Contact:

Re: Multiple native input controls...

Post by PaulMaguire » Fri May 03, 2013 9:35 am

Simon and Jellicle - thanks for this info - will get this implemented.

I like the syntax: focus on nothing - very zen.

When I'm up to speed with LC I will reciprocate. Or if you ever need any help in Director...

Kind regards, Paul.

PaulMaguire
Posts: 44
Joined: Wed Feb 13, 2013 3:38 pm
Location: Glasgow, Scotland
Contact:

Re: Multiple native input controls...

Post by PaulMaguire » Fri May 03, 2013 11:19 am

Hi again.

Ok - I was excited to read the suggestions on the bus into work this morning to get my native input fields sorted. I got in and implemented your suggestions - no dice. The basic issue is that inputReturnKey is never called from a multiline control when return key is hit. Even if I remove my other control (single line, which works perfectly) it fails. As to the rawKeyDown - this needs to be attached to a field. But I am using a native control so this doesn't apply I don't think...

Still confused. The only way I can see out of this is to dynamically scan the input then call 'focus on nothing' if the last character input is return (and delete the return from the input?)

Kind regards, Paul.

PaulMaguire
Posts: 44
Joined: Wed Feb 13, 2013 3:38 pm
Location: Glasgow, Scotland
Contact:

Re: Multiple native input controls...

Post by PaulMaguire » Fri May 03, 2013 12:22 pm

Hello one last time...

Just closure on this thread: I have it working. Not sure if it's best practice, but hey. Here's what I did:
on inputTextChanged
put mobileControlTarget() into tTarget
if (tTarget = "commentInput") then
if the last char of mobileControlGet("commentInput", "text") is RETURN then
focus on nothing
end if
end if
end inputTextChanged
I set the inputTextChanged handler to look out for a return in the comments control. If so, focus on nothing (keyboard hides itself).

Live and learn. Thanks to everyone who offered advice.

Kind regards, Paul.

dk9570
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1
Joined: Sat Jan 06, 2007 4:19 am

Re: Multiple native input controls...

Post by dk9570 » Mon Jun 24, 2013 6:21 pm

I can confirm the same issue on 5.5.4: inputReturnKey() is not sent from the Multi-line input control as documented in the iOS release notes pdf.

I came to the same workaround as Paul and today revisited the issue as the functionality is imperfect for my case.

I'm not sure if the issue persists in 6.x. Hopefully someone will comment here when this is resolved so I can revisit the pros/cons of moving to a newer release.

Thanks

Adrien
Posts: 26
Joined: Fri Jan 09, 2015 9:55 am

Re: Multiple native input controls...

Post by Adrien » Fri Aug 14, 2015 9:08 pm

Using LC 7.0.6, this is still the behavior with the "Done" key of a iOS native multiline field: it inserts "return" instead of sending a "focus on nothing".

This snippet could be a work-around:

Code: Select all

on inputTextChanged
  if mobileControlTarget() is "theNativeMultilineFieldWithTheDoneKey" then -- we definitely need a creative name here
    if mobileControlGet("theNativeMultilineFieldWithTheDoneKey", "text") contains return then -- use "contains" in case the user puts the cursor in the middle of the text and hits the Done key
      lock screen
      put mobileControlGet("theNativeMultilineFieldWithTheDoneKey", "text") into theNativeTextWithNoReturnInIt -- we also need a creative name here
      replace return with empty in theNativeTextWithNoReturnInIt -- we get rid of the return
      mobileControlSet "theNativeMultilineFieldWithTheDoneKey", "text", theNativeTextWithNoReturnInIt
      unlock screen
      focus on nothing
    end if
  end if
end inputTextChanged

Cheers,

Post Reply

Return to “iOS Deployment”