How can I set the tab order for objects (textfields,textbox ect…) on screen.
Hi refer the following code block, I have set the tab order via using submit phase, so as the user submit the text in textField the focus will redirect to declared one.
[lua]
local nameTxtFld
local mobileTxtFld
local emailTxtFld
local txtFldListener=function( event )
if( “submitted” == event.phase ) then
if(event.target.id==1)then
native.setKeyboardFocus(mobileTxtFld)
elseif (event.target.id==2)then
native.setKeyboardFocus(emailTxtFld)
else
native.setKeyboardFocus(nil)
end
end
return true
end
nameTxtFld=native.newTextField(25,30,60,30)
nameTxtFld.anchorY=0
nameTxtFld.id=1
nameTxtFld:addEventListener( “userInput”,txtFldListener )
mobileTxtFld=native.newTextField(25,nameTxtFld.contentBounds.yMax+15,60,30)
mobileTxtFld.anchorY=0
mobileTxtFld.id=2
mobileTxtFld.inputType = “number”
mobileTxtFld:addEventListener( “userInput”,txtFldListener )
emailTxtFld=native.newTextField(25,mobileTxtFld.contentBounds.yMax+15,60,30)
emailTxtFld.anchorY=0
emailTxtFld.id=3
emailTxtFld:addEventListener( “userInput”,txtFldListener )
[/lua]
-Assif
Assif your code is faulty and won’t work.
You have some globals inside txtFldListener since you declare textFields below the listner. Anyway is this really what OP wants?
sierramangment please specify your question, what you exactly wanna achieve with “tab order”. ?
dirindon , the txtfld’s were declared to be at top, you can check now.
I thought anyOne might recognize it, as I have shared it as a sample module. Anyways you did not recognize a Simple thing.
I have updated it for you !!!
- Assif
Well it wasn’t there before, so the code won’t work, if you post some code with mistake and hope someone recognize your mistakes don’t post the code at all. Obviously I did noticed the error thats why i pointed it out, still your code is quite messy and can be optimized but thats just code style and preference, if what you posted is what OP is indeed looking for I would use this reference on event.target in userInput listener instead of “id” and messy “if’s”
i have 23 textfields i have created them in the order i expect. At run time when user choose the first text field (First Name) i want to be able to tab to the next field (LastName ) then to tab to address etc… I need to control when tab button is pressed of the enter button is pressed when editing a field is done, which textfield next gets focus.
Lets assume you have the order of them and its always the same. What I would do :
I would have them all in 1 control table lets say :
“textFieldTable”,
example :
defaultField1 = native.newTextField( 150, 150, 180, 30 ) table.insert(textFieldTable, defaultField1) defaultField2 = native.newTextField( 150, 150, 180, 30 ) table.insert(textFieldTable, defaultField2)
etc to 23. (you can just create control table with all information that is required and there later on in for loop create them from that control table)
Then
local function textListener(event) if (event.phase == "began") then -- do what you need to do here elseif (event.phase == "ended" or event.phase == "submitted") then -- focus on next text field local i = table.indexOf(textFieldTable, event.target) + 1 if textFieldTable[i] then native.setKeyboardFocus(textFieldTable[i]) else native.setKeyboardFocus(nil) end elseif (event.phase == "editing") then -- do what you need to do here end end for i = 1, #textFieldTable do textFieldTable[i]:addEventListener("userInput", textListener) end
You can alter it to represent some graphic effects etc even scene changes, anything actually. If you want assist with your code I will be glad to help you. If you prefer to keep it private just write to me and I can help you out. But I hope what I provided here is enough.
Hi refer the following code block, I have set the tab order via using submit phase, so as the user submit the text in textField the focus will redirect to declared one.
[lua]
local nameTxtFld
local mobileTxtFld
local emailTxtFld
local txtFldListener=function( event )
if( “submitted” == event.phase ) then
if(event.target.id==1)then
native.setKeyboardFocus(mobileTxtFld)
elseif (event.target.id==2)then
native.setKeyboardFocus(emailTxtFld)
else
native.setKeyboardFocus(nil)
end
end
return true
end
nameTxtFld=native.newTextField(25,30,60,30)
nameTxtFld.anchorY=0
nameTxtFld.id=1
nameTxtFld:addEventListener( “userInput”,txtFldListener )
mobileTxtFld=native.newTextField(25,nameTxtFld.contentBounds.yMax+15,60,30)
mobileTxtFld.anchorY=0
mobileTxtFld.id=2
mobileTxtFld.inputType = “number”
mobileTxtFld:addEventListener( “userInput”,txtFldListener )
emailTxtFld=native.newTextField(25,mobileTxtFld.contentBounds.yMax+15,60,30)
emailTxtFld.anchorY=0
emailTxtFld.id=3
emailTxtFld:addEventListener( “userInput”,txtFldListener )
[/lua]
-Assif
Assif your code is faulty and won’t work.
You have some globals inside txtFldListener since you declare textFields below the listner. Anyway is this really what OP wants?
sierramangment please specify your question, what you exactly wanna achieve with “tab order”. ?
dirindon , the txtfld’s were declared to be at top, you can check now.
I thought anyOne might recognize it, as I have shared it as a sample module. Anyways you did not recognize a Simple thing.
I have updated it for you !!!
- Assif
Well it wasn’t there before, so the code won’t work, if you post some code with mistake and hope someone recognize your mistakes don’t post the code at all. Obviously I did noticed the error thats why i pointed it out, still your code is quite messy and can be optimized but thats just code style and preference, if what you posted is what OP is indeed looking for I would use this reference on event.target in userInput listener instead of “id” and messy “if’s”
i have 23 textfields i have created them in the order i expect. At run time when user choose the first text field (First Name) i want to be able to tab to the next field (LastName ) then to tab to address etc… I need to control when tab button is pressed of the enter button is pressed when editing a field is done, which textfield next gets focus.
Lets assume you have the order of them and its always the same. What I would do :
I would have them all in 1 control table lets say :
“textFieldTable”,
example :
defaultField1 = native.newTextField( 150, 150, 180, 30 ) table.insert(textFieldTable, defaultField1) defaultField2 = native.newTextField( 150, 150, 180, 30 ) table.insert(textFieldTable, defaultField2)
etc to 23. (you can just create control table with all information that is required and there later on in for loop create them from that control table)
Then
local function textListener(event) if (event.phase == "began") then -- do what you need to do here elseif (event.phase == "ended" or event.phase == "submitted") then -- focus on next text field local i = table.indexOf(textFieldTable, event.target) + 1 if textFieldTable[i] then native.setKeyboardFocus(textFieldTable[i]) else native.setKeyboardFocus(nil) end elseif (event.phase == "editing") then -- do what you need to do here end end for i = 1, #textFieldTable do textFieldTable[i]:addEventListener("userInput", textListener) end
You can alter it to represent some graphic effects etc even scene changes, anything actually. If you want assist with your code I will be glad to help you. If you prefer to keep it private just write to me and I can help you out. But I hope what I provided here is enough.