Textfield parsing

I am considering the purchase of Corona SDK but am not sure it can function as any thing other than a game building tool. The things I like to do are more in the App and Utility group. They all use the keyboard a lot. First you don’t seem to be able to test any code unless you do the whole thing and purchase the SDK and the Apple ID. You give examples to handle a complete text field:

local function fieldHandler( event )
if (“submitted” == event.phase)
Then …

That seems straight forward. But I want to do something with each letter as it is typed into the text field, before the return button is pressed or another field is touched. In Visual Basic it is called a text change event. Is there an event like that in Lua? If so, how and where do you address it. I lack confidence that this package has what I need. Can anyone help with some answers? Thanks. polycipher [import]uid: 76273 topic_id: 14968 reply_id: 314968[/import]

(Newbie here…)

You can test everything in the simulator for free, not sure if you can do app builds without a license; somebody else can speak to that.

It sounds like what you would need is to use addEventHandler to detect the “touch” of the button and then write some sort of custom function for the output?

if event.target.id == "pressZ" then textfield.text = "Yum!" end

That would take place instantaneously upon pressing whatever button(s) have “pressZ” as an ID. I can’t speak to the efficacy of the native.keyboard extension but you should be able to add code to that or build your own from the ground up…

[import]uid: 41884 topic_id: 14968 reply_id: 55245[/import]

richard9,
Thanks for the input. I think what I need is a list of all possible events relating to the textfields and native.keyboard. That way I can chose what seems best for my situation. Does anyone know where to find such a list if it exists?
[import]uid: 76273 topic_id: 14968 reply_id: 55353[/import]

Well, the events list is pretty to the point, depending on what you need. I see your concern though (native.newTextField has different event mechanics than everything else.) It’s really hard to specify an exact approach without getting an idea of what you want to do.

That being said, two things:

  1. I think somebody asked for exactly what you’re looking for already. :slight_smile:

Basically, try and see if the phase “editing” works.

  1. List of Major Event Types
  2. Everything about touching the screen is in the Touch Event Types section.

Hopefully that new event phase works, because otherwise you’d need to do something tricky like make a keyboard mask and detect touches through that… [import]uid: 41884 topic_id: 14968 reply_id: 55524[/import]

Thank you richard9 for the time and the input for my problem. It means a lot that you have responded, thanks.
Imagine I am typing the word HELP. I touch the H key and at that point I want to assign the length of the string to i.
1 s = textfield1.text
2 i = string.len(s)
3 c = string.sub(s,i,1) --This should get the last character in the string. “H”
Type E and;
4 c = string.sub(s,i,1) – This should get the last character in the string. “E”
Etc. except that these would be shortened to a function call. Each time a letter is typed,
it would be delt with using Function: rawget (table, index) to pick up a different character or value.
I realize a lot has been left out, but each time a character is typed it SHOULD be considered a textfield change event. The problem is there is no “change” event listed that I can find.

Best regards, polycipher@gmail.com [import]uid: 76273 topic_id: 14968 reply_id: 55663[/import]

(When you paste in code here, encapsulate it with the < code > < / code > tags (see below the posts!). Makes it way easier to read.)

Yeah, so it sounds like what you would do is add an event listener to the TextField that uses event.editing, since that is called on every keystroke. Is that the change event you were looking for?

API changes: event.oldString is now event.oldText
v_event.startPosition now starts at index=1 instead of 0
v_event.text is introduced to show the new/current string
v_event.newCharacters and event.numDeleted are unchanged. (556) - case 5670
– print("\tnewCharacters="…tostring(v_event.newCharacters))
print("\toldText", tostring(v_event.oldText))
print("\tposition", tostring(v_event.startPosition))
print("\tnumDeleted", tostring(v_event.numDeleted))
print(‘cur txt=’…self.text)

That seems like some more useful things to call although I don’t quite understand what they mean yet. I’m guessing that event.oldText is the text typed up to that point before the keypress?

[import]uid: 41884 topic_id: 14968 reply_id: 55771[/import]

richard9, I think this is the time that ANSCA should step forward with clarification on this issue if they can. They have the most control and experience with the Corona SDK and Lua.
I don’t intend to purchase Corona without factual information and at this point there is a void in that area. Thanks for your efforts, polycipher. [import]uid: 76273 topic_id: 14968 reply_id: 55817[/import]

Well I’m just saying you could try to craft some of that on your own, but yeah, maybe someone will pipe up. I’d try something like that myself but I don’t have a Mac (yet). [import]uid: 41884 topic_id: 14968 reply_id: 55827[/import]