Getting input from multiple native.newTextFields with one listener?

Hello!

From the documentation for the native new text fields, the following multiple inputs are using the same listener:

[lua]

local defaultField, numberField – forward reference (needed for Lua closure)

– TextField Listener

local function fieldHandler( getObj )

     

     – Use Lua closure in order to access the TextField object

     

     return function( event )

          

          print( "TextField Object is: " … tostring( getObj() ) )

          

          if ( “began” == event.phase ) then

               – This is the “keyboard has appeared” event

               

          elseif ( “ended” == event.phase ) then

               – This event is called when the user stops editing a field:

               – for example, when they touch a different field or keyboard focus goes away

               

               print( "Text entered = " … tostring( getObj().text ) )         – display the text entered

               

          elseif ( “submitted” == event.phase ) then

               – This event occurs when the user presses the “return” key

               – (if available) on the onscreen keyboard

               

               – Hide keyboard

               native.setKeyboardFocus( nil )

          end

     end     – “return function()”

     

end

– Create our Text Field

defaultField = native.newTextField( 10, 30, 180, 30 )

local function defaultHandler( event )

     fieldHandler( function() return defaultField end ) – passes the text field object

end

defaultField:addEventListener( “userInput”, defaultHandler )

numberField = native.newTextField( 10, 70, 180, 30 )

local function numberHandler( event )

     fieldHandler( function() return numberField end )

end

numberField:addEventListener( “userInput”, numberHandler )

[/lua]

How can I get the entered text from each one of the fields at a later time after a user has entered data in all the fields, and not as the events are fired off? I have a user entering his/her first and last name and then a submit button. I want to be able to get the info once the user has hit the submit button.

Appreciate any help!

-Mario

I am doing a variety of input on multiple fields at once, but not based on the corona sample.

My code uses the nativeText.text field of the edit object to access the native fields current text value. When the edit completes, I am removing the native field, and setting the text into my own onscreen display.newText object (with a white roundedRect box behind it) to hold the text. Native fields have too many issues for me to leave them onscreen all the time with what my app is doing…

A word to the wise… If you’ve got serious text entry challenges, you’ll want to look into moving your code so that there’s only one native textfield on screen at a time… And it’s only there while the popup keyboard is active…

OK, so nativeText.text is the best way to go. I wasn’t seeing any values (even after setting them manually) because on Windows, the native text inputs don’t work in the simulator. On my mac, I printed the values of nativeText.text and they showed right up.

So the answer like you said is “nativeText.text”. w00t!

-Mario

I am doing a variety of input on multiple fields at once, but not based on the corona sample.

My code uses the nativeText.text field of the edit object to access the native fields current text value. When the edit completes, I am removing the native field, and setting the text into my own onscreen display.newText object (with a white roundedRect box behind it) to hold the text. Native fields have too many issues for me to leave them onscreen all the time with what my app is doing…

A word to the wise… If you’ve got serious text entry challenges, you’ll want to look into moving your code so that there’s only one native textfield on screen at a time… And it’s only there while the popup keyboard is active…

OK, so nativeText.text is the best way to go. I wasn’t seeing any values (even after setting them manually) because on Windows, the native text inputs don’t work in the simulator. On my mac, I printed the values of nativeText.text and they showed right up.

So the answer like you said is “nativeText.text”. w00t!

-Mario