iOS text field

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4178
Joined: Sun Jan 07, 2007 9:12 pm

Re: iOS text field

Post by bn » Thu Mar 15, 2012 10:07 pm

Hi Nakia,

I think it is a design decision and what you feel comfortable with.

Design decision regarding how you want to interact with your users and what they

You could also very well just use one native input field and set its rect on the fly and controlling the type of keyboard. This could be done on a locked field that is not focusable in a mousedown handler. There you would overlay the input field over the text field, let the user type his input. When the user is done you transfer the text to the destination field and hide the native input controller.

It is probably a little less code if you use only one native input control.

I find it difficult to give advice because all approaches work and depend on personal preferences and specific circumstances. In your case as I understand especially that you want numeric input into the third field only. Though there are ways to control for numbers only with a Livcode field.

Kind regards

Bernd

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: iOS text field

Post by Nakia » Fri Mar 16, 2012 12:13 am

As you say I would prefer to use only one iOS text fld and be able to set its rect to the focus of the fld they have pressed but just can't seem to get in my head how to do this..

It seems that when I use the iOS text fld placed over the rect of the underlying text fld the text fld doesn't receive the press so using the focus or open fld handler won't work to apply any actions..

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: iOS text field

Post by Nakia » Fri Mar 16, 2012 8:59 am

think I am getting closer, but still one small bug I need to address...

If I am in one of the IOS Text fields and press into one of the other flds it doesn't send either of the termination messages to the current Text Field (as it is named the same as the new one that is created when I pressed into the new fld) if I press return or anywhere else it exists just fine and does what needed..

It seems I need to name each of them uniquely when created but how do I then use the inputEndEditing and inputReturnKey correctly as they don't seem to have an index of their origin?

this is what I ended up with in the fld scripts (below example of one), each places its object name into gUiTextField..
on mouseDown
global gUiTextField
put "PilotName" into gUiTextField
UiTextField
end mouseDown
below is the card script..

Code: Select all

on UiTextField
   
   
      iphoneControlCreate "input"
      put the result into inputID
      --
      iphoneControlSet inputID, "rect", the rect of fld gUiTextField
      iphoneControlSet inputID, "visible", "true"
      iphoneControlSet inputID, "opaque", "false"
      iphoneControlSet inputID, "clearButtonMode", "unless editing"
      iphoneControlSet inputID, "autoCapitalizationType", "none"
      iphoneControlSet inputID, "autoCorrectionType", "No"
      iphoneControlSet inputID, "autoClear", "false"
      --

   
end UiTextField

on inputBeginEditing
   put empty into fld gUITextField
end inputBeginEditing

on inputEndEditing
   put iphoneControlGet (inputID, "text") into fld gUiTextField
   iphoneControlDelete inputID
end inputEndEditing

on inputReturnKey
   put iphoneControlGet (inputID, "text") into fld gUiTextField
   iphoneControlDelete inputID
end inputReturnKey
  

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4178
Joined: Sun Jan 07, 2007 9:12 pm

Re: iOS text field

Post by bn » Fri Mar 16, 2012 9:32 am

Hi Nakia,
how do I then use the inputEndEditing and inputReturnKey correctly as they don't seem to have an index of their origin?
iPhoneControlTarget() will tell you which control issued the message. -> Dictionary.

Code: Select all

put iPhoneControlTarget() into tWhoDidIt
if you use this it is maybe easier to name the controls when they are created instead of using the default id-number.
kind regards

Bernd

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: iOS text field

Post by Nakia » Fri Mar 16, 2012 12:14 pm

Okay,

I think you are right...
I will see how I go, been working on another portion tonight

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4178
Joined: Sun Jan 07, 2007 9:12 pm

Re: iOS text field

Post by bn » Fri Mar 16, 2012 9:02 pm

Hi Nakia,

I made a little stack that uses three iOS native input fields. The fields are created on preopencard and deleted on closeCard.
The size of the iOS field is determined by three hidden Livecode fields. (you can make them visible with a checkbox)

The input from the three iOS fields goes into 3 lines of a field "fEntries"

Line 1 is name
line 2 is surname
line 3 is ASAA number

you can redirect the input wherever you want, see comments in the code of the card script.

the field for the ASAA number checks for numbers. Right now it also accepts "/" and "-" in case these are alowable, change in script which characters are allowed, see comments.
Checking for numbers works ok unless someone pastes text into the field. If you want to change that I could rewrite that part.

Have a look
Nakia3FieldsInput_0.0.2.livecode.zip
(3.15 KiB) Downloaded 276 times
kind regards

Bernd

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: iOS text field

Post by Nakia » Fri Mar 16, 2012 10:47 pm

Thank you so much....

I will take a look and report back :D

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: iOS text field

Post by Nakia » Sat Mar 17, 2012 12:56 am

this looks good so far..(have simplified down a little to start with)

One question though..
I am using this to place the information into its approriate fld which is working as required...

Code: Select all

put  iPhoneControlGet (tTarget, "text") into fld tTarget
But i then have another script in a btn that takes the contents of these 3 LC flds and places them into another fld..how do I add to that script the ability to reset the values in each of the IOSTextFlds?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4178
Joined: Sun Jan 07, 2007 9:12 pm

Re: iOS text field

Post by bn » Sat Mar 17, 2012 1:08 am

Hi Nakia,

here is a little command you place in the card script assuming the card script still has the same script local variables etc.

Code: Select all

on clearInputFields
   repeat for each item anInputField in sFields
      iPhoneControlSet anInputField, "text", ""
   end repeat
end clearInputFields
When you have put your data to its final destination you can issue a

Code: Select all

-- code that puts your data to final destination
clearInputFields
-- possibly more code
in that same handler and it will empty the iOS input fields

kind regards

Bernd

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: iOS text field

Post by Nakia » Sat Mar 17, 2012 1:53 am

perfect thanks so much.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4178
Joined: Sun Jan 07, 2007 9:12 pm

Re: iOS text field

Post by bn » Thu Mar 22, 2012 12:58 pm

Hi Kia,
As noted earlier on each IOS Text Field places its contents in a LC text fld on end editing msg..this works fine if i press return or any where on the screen but doesn't work if i press button which activates another function whilst in IOS Text FLD.. I.E. there is a button on this card which takes the contents of the 3 LC Text Flds and places them into another fld..If i just press that button the IOS text fld doesn't send its endInput message and therefore doesnt place the data in the LC Text Fld..

why did you delete the post? Is the problem solved?

Anyways:
add "focus on nothing" and it should work.

Code: Select all

on addPilotDetails
   focus on nothing -- this forces the keyboard to close and the inputEndEditing messages is sent
   put "add Pilot" into field "fErr"
end addPilotDetails
Kind regards

Bernd

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: iOS text field

Post by Nakia » Mon Mar 26, 2012 2:36 am

Yep , solved it by changing the IOS Text fld to place the data into the field on the inputTextChanged message in place
Of inputEndEditing message.

I did try the focus on nothing in the button script but it didn't seem to work...


Thanks

Kia

Post Reply