This is a continuation of the discussion from the API page. http://developer.anscamobile.com/reference/index/nativenewtextfield#comment-98113 [import]uid: 7559 topic_id: 24285 reply_id: 324285[/import]
I hate to pile on, but this is not very useful without a return key for inputType=“number” or a way to get the text keyboard in number mode.
Time to look at widgets. [import]uid: 58455 topic_id: 24285 reply_id: 98394[/import]
Someone asked if we should be removing the listeners we are creating for these input fields. Any examples?
My own question is that there seem to be some huge differences in positioning of input text fields from the emulator to device. I am using build 2012.777 - are there some bugs in this version or am I missing something? Input fields are aligning perfectly on the Mac emulator for all device builds - this is after I changed the x/y positions to take global coordinates as stated in the documentation and changed the listener code the latest syntax.
Many thanks [import]uid: 83823 topic_id: 24285 reply_id: 98875[/import]
I have been able to get closer to the root of the problem. I am currently adding the input boxes to an existing group after they are created, so I can cycle through the group later and remove all items.
In the emulator, the input boxes retain their X/Y coordinates after they are placed in a group - on the device though, the input-boxes seem to use the coordinate space of the group they are in.
I will experiment with putting them in an empty group and see what coordinate space is used then. [import]uid: 83823 topic_id: 24285 reply_id: 98983[/import]
None of the native object will work in groups. Here is a note from the Text Field API page:
Note: Native Text Field objects, like other native objects don’t work in groups and are always displayed on top of regular Display Objects (vector, images, and text).
[import]uid: 7559 topic_id: 24285 reply_id: 99022[/import]
I’m assuming this means native display objects also won’t work in the scrollview widget? [import]uid: 62323 topic_id: 24285 reply_id: 99102[/import]
Hi Tom
Thanks for your reply, obviously on the device, the positions of the native input boxes are being affected by groups even though they are not supposed to be.
S [import]uid: 83823 topic_id: 24285 reply_id: 99155[/import]
Out of curiosity, do you plan on making textfields available to Windows users anytime soon? [import]uid: 140942 topic_id: 24285 reply_id: 100101[/import]
Hi, i just got a deprecation warning on the code (the same as alan120184):
WARNING: The ‘listener’ argument to native.newTextField( left, top, width, height [, listener] ) is deprecated. Call the object method o:addEventListener( ‘userInput’, listener ) instead.
It this bit of code from http://developer.anscamobile.com/forum/2011/07/12/textfield-limited-length :
-- 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
function chknum()
defaultField.text = string.sub(defaultField.text,1,6)
end
Runtime:addEventListener("enterFrame",chknum)
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
Runtime:removeEventListener("enterFrame",chknum)
native.setKeyboardFocus( nil )
end
end -- "return function()"
end
-- Create our Text Field
defaultField = native.newTextField( 10, 30, 180, 30,
fieldHandler( function() return defaultField end ) )
it runs fine, but i get the warning. i’m on build #786.
if it is, i would love some help getting the code above working!
this is as far as i’ve got, it runs without errors, but it doesn’t limit the max number of characters for the text field (which is what i’m trying to do).
-- 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
function chknum()
nameField.text = string.sub(nameField.text,1,6)
end
Runtime:addEventListener("enterFrame",chknum)
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
Runtime:removeEventListener("enterFrame",chknum)
native.setKeyboardFocus( nil )
end
end -- "return function()"
end
-- Create our Text Field
nameField = native.newTextField( 10, 30, 180, 30)--, fieldHandler( function() return defaultField end ) )
nameField:addEventListener('tap', fieldHandler( function() return defaultField end ))
thank you!! [import]uid: 121467 topic_id: 24285 reply_id: 103750[/import]
I havn’t tested your code or anything but the only thing I noticed was in the last line. ‘tap’ should be ‘userInput’.
nameField:addEventListener('userInput', fieldHandler( function() return defaultField end ))
[import]uid: 56820 topic_id: 24285 reply_id: 103752[/import]
wait-it’s working fine in the simulator, having trouble running on the device… will update my post once i can get it working again! [import]uid: 121467 topic_id: 24285 reply_id: 103770[/import]
The multiline has a ‘hasBackground’ property to remove the white box and let us customize the design a bit more. Any chance of this being part of the single line text input? [import]uid: 6317 topic_id: 24285 reply_id: 103881[/import]
How to make it uneditable? I tried to use textbox but all of my boxes are single line, it sometimes messed up by showing the scroll bar. I don’t like it and I want to use the textfield since it’s dedicated for single line.
So the problem is it doesn’t have a property like textbox.isEditable
Any idea? [import]uid: 4187 topic_id: 24285 reply_id: 104042[/import]
I’d also like to see this feature implemented. ‘hasBackground’ is a must have.
Any workarounds for a text field with similar behavior that we can ‘style’ completely ? I don’t want the white background, have created my own input field graphics.
[import]uid: 134089 topic_id: 24285 reply_id: 105211[/import]
anderoth, the code appears to be working on the device now! thanks very much! [import]uid: 121467 topic_id: 24285 reply_id: 105215[/import]
Is there any way to let the keyboard popup without capslock/shift turned on? [import]uid: 136249 topic_id: 24285 reply_id: 105665[/import]
Does anyone know how to do this? [import]uid: 136249 topic_id: 24285 reply_id: 107857[/import]
Come on… at least give a response if it’s not possible.
I tried setting the input type of my field to “email” but it still starts with “shift” turned on. [import]uid: 136249 topic_id: 24285 reply_id: 108041[/import]
Sorry, but there are no options to set the cap locks on the text keyboard. [import]uid: 7559 topic_id: 24285 reply_id: 108072[/import]
Is it possible to restrict the amount of characters the user is able to type? For example, I’d like the user to enter the capacity of their pool in gallons and I don’t want them to be able to enter an input larger than 6 characters. I’ve already restricted the input to “number”.
Thanks,
Alex [import]uid: 139917 topic_id: 24285 reply_id: 108202[/import]