How to use one function for all text fields?

I use the following code for each function for the addEventListener of my text fields. I have one scene that has 50 text fields and I hate to make 50 functions. Is there any way to write one to use for all?

My concern is for the transition.to line how will it know what the y value will be to move it up on the screen? 

Thanks,

Warren

local function onPurchPrice( event ) if ( "began" == event.phase ) then transition.to( editGroup, { time=350, x=0, y=0, onComplete=listener1 } ) elseif ( "editing" == event.phase ) then local txt = event.text if(string.len(txt)\>50)then txtPurchPrice.text = string.sub(txt, 1, 50) end elseif ( "submitted" == event.phase ) then native.setKeyboardFocus( nil ) transition.to( editGroup, { time=350, x=0, y=0, onComplete=listener1 } ) end end

As you know lua is objective programing language so basicially what you can do, is adding all of them to table:

MyAllTextFields = {}

then for i=1, #myalltextfields do

-----Add your function here

end

That would save you a lot of time i know it might not be best solution but it should work.

As you know lua is objective programing language so basicially what you can do, is adding all of them to table:

MyAllTextFields = {}

then for i=1, #myalltextfields do

-----Add your function here

end

That would save you a lot of time i know it might not be best solution but it should work.