Force Input Control to Enter Edit Mode

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Force Input Control to Enter Edit Mode

Post by dcpbarrington » Sun Jun 30, 2013 1:46 am

Forum,

I have a basic Android Input Control question.

I have set up a card with several input field. In each of the fields I have the following code and are set to Focus-able with Text Locked.

on touchStart pID
put the long id of me into tName
put the text of me into tContent
inputCreatorWide "firstInput", "input", tName, tContent, "alphabet", "words", "no", "Done", ""
end touchStart

inputCreatorWide is a method in the card as follows. (for some reason the CODE button does not work)

on inputCreatorWide pName, pKind, pFld, pContent, pKeyboardType, pAutoCap, pAutoCorrect, pReturn, pDataDetect

if pFld contains "stack" then
put wordOffset("stack",pFld) into tWord
put word 1 to (tWord -2) of pFld into pFld
end if
put the rect of pFld into tSize
put the height of pFld into tHeight
set the itemdel to ","
add tHeight to item 4 of tSize -- Double the field size
mobileControlCreate pKind, pName
mobileControlSet pName, "rect", tSize -- standard for all controls
mobileControlSet pName, "visible", "True" -- standard for all controls
mobileControlSet pName, "text", pContent -- standard for all controls
mobileControlSet pName, "fontSize", 9
mobileControlSet pName, "textAlign", "left"
mobileControlSet pName, "keyboardType", pKeyboardType
mobileControlSet pName, "autoCapitalizationType", pAutoCap
mobileControlSet pName, "autoCorrectionType", pAutoCorrect

if pReturn is not Empty then
mobileControlSet pName, "returnKeyType", pReturn
else
mobileControlSet pName, "returnKeyType", "default"
end if
mobileControlSet pName, "contentType", "plain"
mobileControlSet pName, "editable", "TRUE"
mobileControlSet pName, "scrollingEnabled", "TRUE"

end inputCreatorWide

I has have a RETURN key handler that places the text that the user entered into the field and deletes the Input Control for that field.
on inputReturnKey
put mobileControlTarget() into tTarget
put mobileControlGet( tTarget, "text" ) into tInputValue
mobileControlDelete tTarget
switch tTarget
case "firstInput"
put tInputValue into fld "FirstName"
break
case "lastInput"
put tInputValue into fld "LastName"
break
end switch

end inputReturnKey

on inputBeginEditing
end inputBeginEditing

on inputTextChanged
end inputTextChanged

on inputEndEditing
put mobileControlTarget() into tTarget
mobileControlDelete tTarget
end inputEndEditing

This is the PROBLEM.
When the user selects the Input Field the Input Control is created and a white box is drawn in the specified area. The user then needs to touch the input area to put it in EDIT mode. If they touch somewhere else another input control can be created.

I want to put the user directly into EDIT mode when the Input Control is created. Then if they leave the control it gets the InputEndEditing message and is deleted.

I must be missing something simple. I tried to PASS the TouchStart message, that didn't help.
Thanks for the help.

JacobS
Posts: 58
Joined: Mon Aug 20, 2012 8:41 pm

Re: Force Input Control to Enter Edit Mode

Post by JacobS » Wed Jul 03, 2013 10:35 pm

Hi Barrington,

I think what you might be looking for is setting the focus to the field you just created. I have an app that loads a screen that auto-focuses on a field and pops up a keyboard so the user doesn't have to touch it in order to start editing.

This is how I do it:

Code: Select all

on inputCreate
   if "testinput" is among the lines of mobileControls() then
      inputDelete
   end if   
   mobileControlCreate "multiline", "testinput"
   //update a bunch of field properties here...
   inputFocus //function to focus on the input
end inputCreate

on inputFocus
   mobileControlDo "testinput","enabled","true" //make sure the input is focus-able
   mobileControlDo "testinput", "focus"             //actually focus on the field so the keyboard pops up, etc.
end inputFocus
The comments in the inputFocus() command tells you what that command does. That command is the most important part of this code snippet, in your case.

For you, I would just stick the two lines of the inputFocus() command right before the "end inputCreatorWide" statement. So it would be:

Code: Select all

     ...
     mobileControlSet pName, "scrollingEnabled", "TRUE"

     mobileControlDo pName,"enabled","true" //make sure the input is focus-able
     mobileControlDo pName, "focus"             //actually focus on the field so the keyboard pops up, etc.
end inputCreatorWide
Hope that helps.
Jacob

P.S. It's strange that the "code" button doesn't work, but you can write "(bracket)code(endbracket).....(bracket)/code(endbracket)" around your code in a post to bypass using that button! :)

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: Force Input Control to Enter Edit Mode

Post by dcpbarrington » Mon Jul 08, 2013 9:38 pm

Jacob,

Thank you so much for your response. Unfortunately I'm using Android and not iOS. It looks like the "Focus" command is not available based on the release Notes in LiveCode V5.5.5
I will need to document that the user needs to double Touch to activate the keyboard.

If I cannot set the FOCUS, I need to make sure that another control cannot be started. Here is what I did.

<Code>
on inputCleanUp
put mobileControls() into tControlList
repeat for each line tControl in tControlList
mobileControlDelete tControl
end repeat
end inputCleanUp
</Code>

I then do a CleanUp when ever a new field is opened. I also needed to add the cleanup to when the user touches other locations on the card.

Thanks for the help.

JacobS
Posts: 58
Joined: Mon Aug 20, 2012 8:41 pm

Re: Force Input Control to Enter Edit Mode

Post by JacobS » Thu Jul 11, 2013 9:30 pm

You're right! I guess I never noticed that the keyboard doesn't pop up on the Android platform. I'm used to using iOS so that's probably why I thought it worked. It is kind of strange that when you used the "Focus" command that the cursor will appear in the field, but the keyboard doesn't pop up. Maybe it should be reported as a bug?
In any case, glad to hear you figured out a work-around.

Jacob

Post Reply