Page 1 of 1
Multiple native input controls...
Posted: Mon Apr 29, 2013 3:25 pm
by PaulMaguire
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.
Re: Multiple native input controls...
Posted: Mon Apr 29, 2013 11:38 pm
by Jellicle
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
Re: Multiple native input controls...
Posted: Tue Apr 30, 2013 9:41 am
by PaulMaguire
Excellent - I'll check it out. Thanks.
Re: Multiple native input controls...
Posted: Thu May 02, 2013 1:20 pm
by PaulMaguire
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.
Re: Multiple native input controls...
Posted: Thu May 02, 2013 8:49 pm
by Simon
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
Re: Multiple native input controls...
Posted: Fri May 03, 2013 4:59 am
by Jellicle
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.
Re: Multiple native input controls...
Posted: Fri May 03, 2013 9:35 am
by PaulMaguire
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.
Re: Multiple native input controls...
Posted: Fri May 03, 2013 11:19 am
by PaulMaguire
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.
Re: Multiple native input controls...
Posted: Fri May 03, 2013 12:22 pm
by PaulMaguire
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.
Re: Multiple native input controls...
Posted: Mon Jun 24, 2013 6:21 pm
by dk9570
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
Re: Multiple native input controls...
Posted: Fri Aug 14, 2015 9:08 pm
by Adrien
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,