native.newTextField

I have to say that the keyboard input issue is very disappointing and will probably mean trying something else for developing cross-platform mobile applications. Everything was going great until this issue came up. I’m not particularly crazy about Lua for business apps (untyped variables just seem like a bad idea) but I can get around that with careful coding. It’s not truly object-oriented but then, nothing was when I started programming.

The lack of support for real text inputs, though and the length of time the issue seems to have been ignored (people have been asking for support on the Windows simulator for at least 1 year) are making me question the sanity of continuing down this path.

The Corona developers seem to be interested in pushing Corona as a viable option for business applications. This page (http://www.coronalabs.com/products/corona-sdk/, for instance, states:

From games to eBooks to business apps, Corona is unmatched in giving mobile app developers the ability to develop high quality content at record speeds.

Where is the actual evidence of any intention to support that claim? How is it that Adobe AIR, Titanium and even HTML5/PhoneGap manage to have text input boxes but Corona does not?

Sorry for the long rant but I thought I had finally found a platform worth committing myself to until just discovering this issue. More research is in order but it’s certainly not looking good. [import]uid: 156068 topic_id: 24285 reply_id: 135823[/import]

It is true… corona need improvements in this area to allow us make better business apps… [import]uid: 6732 topic_id: 24285 reply_id: 137272[/import]

For all you wanting TextFields with transparency and more TextBox features, here is a workaround:

\*\*\* Code example for Single line TextBox input to enable TextField-like input with transparency and other features.  
\*\*\* Only tested in Xcode simulator for iOS  
  
labelFont = gameUI.newFontXP{ ios="Cantarell-Bold", android=native.systemFont } -- This is a free truetype font that I use in my game  
  
-- Globals:  
   
statLabel=nil  
statText="Player"  
textBox=nil  
  
-- We start with defining the handle that is called when anything happens in the text box:  
  
local function textHandle( getObj )  
 return function( event )   
 if ( "began" == event.phase ) then  
 -- Text field is active  
 elseif ( "ended" == event.phase ) or ( "submitted" == event.phase ) or ("editing"== event.phase) then  
 -- This event is called when the user stops editing or enters something in a field:  
 statText= tostring( getObj().text )  
 textreturn=string.find(statText,string.char(10),1) -- Look for "return" character  
 if textreturn~=nil then  
 -- user pressed return button, so remove "return" from text field (it should not be more than one line)  
 statText=string.gsub( statText, string.char(10), "" )  
 end  
 statLabel.text=statText  
 if statLabel.width\>600 then  
 -- new object too wide; have to limit text length to prevent dual line textbox  
 statText=string.sub(statText,1,string.len(statText)-1)  
 statLabel.text=statText  
 end  
 for m=1,string.len(statLabel.text) do  
 if string.find(statLabel.text, " ", -1)~=nil then  
 -- iOS centering of text disregards spaces after last character, so Corona text must also do this:  
 statLabel.text=string.sub(statLabel.text,1,string.len(statLabel.text)-1)  
 end  
 end  
 if textBox.text~=statText then  
 -- only update text box text if strictly necessary (will move cursor)  
 textBox.text = statText  
 end  
 if ("editing"~= event.phase) or textreturn~=nil then  
 -- if event was ended or submitted, or return pressed, remove focus from field..  
 native.setKeyboardFocus( nil )  
 end  
 end  
 end -- "return function()"  
end  
  
-- Then we set up the text box:  
  
textBox = native.newTextBox( 11, 70+43, 620, 78  
textBox:addEventListener( 'userInput',  
function ()   
 return textBox  
end ) )  
textBox:setTextColor( 0, 0, 255, 255 )  
textBox.hasBackground = false  
textBox.align = "center" -- correct alignment/placement only shows up on device or Xcode, not Corona simulator  
textBox.text = statText  
textBox.font = native.newFont( "Cantarell-Bold", 20 ) -- This is a free truetype font that I use in my game  
textBox.inputType = "default"  
textBox.alpha = 0.5  
textBox.isEditable = true  
textBox.y = 70+82  
  
-- This is optional: It puts a Corona text object beneath the iOS object; only shown as example. The reason to have this is that Corona objects can be made more appealing (shadowing, outlining, multicolor and so on..).  
statLabel=display.newText(statText, display.contentWidth/2, 130, labelFont, 40 )  
statLabel.x=statLabel.x-(statLabel.contentWidth/2)  
statLabel:setTextColor( 255, 255, 255, 255 )  
  
-- Note: text box text has a tendency to shift 1 pixels in some instances in comparison to corona text. You may want to use non-bold font for the text object to compensate for this.  

This source code has been cut out from a larger program, so there may be typos. Please also note that the cursor will move to the end of the field if you edit the textbox text during typing (like removing non-allowed characters or alike).

Anyway, hope it helps someone!

Best,
Renato
Microingress Ltd [import]uid: 141323 topic_id: 24285 reply_id: 137502[/import]

[censored] unsubscribe for this thread on this site doesn’t work!!!
[import]uid: 81188 topic_id: 24285 reply_id: 137538[/import]

I’m sorry this is frustrating you @jkrassman. Can you tell me the steps you are doing to unsubscribe? I’ll see what I can do to help.

Also if it’s not too much to ask, keep in mind we do have younger forum members and if you could avoid profanity, it would be greatly appreciated.

[import]uid: 199310 topic_id: 24285 reply_id: 137559[/import]

Renato,

Thanks for publishing the code but it actually highlights my second biggest frustration with the Corona platform – everything is so iOS oriented. For instance, in many of the replies on this forum, the first answer will often provide an answer which only works on the xCode or iOS simulator but not on Windows. I don’t want to start a battle over which is better but I do expect a commercial tool to provide proper support for the platform I choose to operate in. If Corona were open-source, the situation would be different.

I did manage to create a workaround to the textInput issue which would be acceptable with just a few more tweaks. It automatically creates a native textInput off screen which is tied to a Widget Candy textbox for the UI. It includes a property which allows you to specify an amount to offset the y position when the on-screen keyboard is displayed. Actually, it allows you to specify what group should be moved. It then handles the keyboard events from the native textInput and changes the WidgetCandy text to match. When executed from the simulator, it simply moves group and waits for input.

This all works and, if that were the only issue, I would probably go ahead and commit to Corona. I am, however, very concerned that other issues will come up which might not be so easy to get around. If I were making nothing but games, Corona would be my first choice. For other types of applications, it simply not a suitable tool. Personally, I plan to keep an eye on it’s development and hopefully Ansca will decide to actually update the tool to better support a Windows development environment and creating non-game related applications. I’ve evaluated almost every cross-platform development tool I could find and have decided that Adobe Air using as3 and Starling/Feathers best meets my requirements.

If anyone is interested in the textInput code mentioned above, let me know. Just keep in mind it was created by a complete Conrona noobie and there’s no way I can support it (since I won’t be using Corona). [import]uid: 156068 topic_id: 24285 reply_id: 137629[/import]

maxapps - Thank you for posting and the feedback. Would you mind if I email you directly in order to ask a few questions and get some feedback on how we can improve this? This is an important area for us and we intend to improve here.
David [import]uid: 10668 topic_id: 24285 reply_id: 137648[/import]

It is true… corona need improvements in this area to allow us make better business apps… [import]uid: 6732 topic_id: 24285 reply_id: 137272[/import]

For all you wanting TextFields with transparency and more TextBox features, here is a workaround:

\*\*\* Code example for Single line TextBox input to enable TextField-like input with transparency and other features.  
\*\*\* Only tested in Xcode simulator for iOS  
  
labelFont = gameUI.newFontXP{ ios="Cantarell-Bold", android=native.systemFont } -- This is a free truetype font that I use in my game  
  
-- Globals:  
   
statLabel=nil  
statText="Player"  
textBox=nil  
  
-- We start with defining the handle that is called when anything happens in the text box:  
  
local function textHandle( getObj )  
 return function( event )   
 if ( "began" == event.phase ) then  
 -- Text field is active  
 elseif ( "ended" == event.phase ) or ( "submitted" == event.phase ) or ("editing"== event.phase) then  
 -- This event is called when the user stops editing or enters something in a field:  
 statText= tostring( getObj().text )  
 textreturn=string.find(statText,string.char(10),1) -- Look for "return" character  
 if textreturn~=nil then  
 -- user pressed return button, so remove "return" from text field (it should not be more than one line)  
 statText=string.gsub( statText, string.char(10), "" )  
 end  
 statLabel.text=statText  
 if statLabel.width\>600 then  
 -- new object too wide; have to limit text length to prevent dual line textbox  
 statText=string.sub(statText,1,string.len(statText)-1)  
 statLabel.text=statText  
 end  
 for m=1,string.len(statLabel.text) do  
 if string.find(statLabel.text, " ", -1)~=nil then  
 -- iOS centering of text disregards spaces after last character, so Corona text must also do this:  
 statLabel.text=string.sub(statLabel.text,1,string.len(statLabel.text)-1)  
 end  
 end  
 if textBox.text~=statText then  
 -- only update text box text if strictly necessary (will move cursor)  
 textBox.text = statText  
 end  
 if ("editing"~= event.phase) or textreturn~=nil then  
 -- if event was ended or submitted, or return pressed, remove focus from field..  
 native.setKeyboardFocus( nil )  
 end  
 end  
 end -- "return function()"  
end  
  
-- Then we set up the text box:  
  
textBox = native.newTextBox( 11, 70+43, 620, 78  
textBox:addEventListener( 'userInput',  
function ()   
 return textBox  
end ) )  
textBox:setTextColor( 0, 0, 255, 255 )  
textBox.hasBackground = false  
textBox.align = "center" -- correct alignment/placement only shows up on device or Xcode, not Corona simulator  
textBox.text = statText  
textBox.font = native.newFont( "Cantarell-Bold", 20 ) -- This is a free truetype font that I use in my game  
textBox.inputType = "default"  
textBox.alpha = 0.5  
textBox.isEditable = true  
textBox.y = 70+82  
  
-- This is optional: It puts a Corona text object beneath the iOS object; only shown as example. The reason to have this is that Corona objects can be made more appealing (shadowing, outlining, multicolor and so on..).  
statLabel=display.newText(statText, display.contentWidth/2, 130, labelFont, 40 )  
statLabel.x=statLabel.x-(statLabel.contentWidth/2)  
statLabel:setTextColor( 255, 255, 255, 255 )  
  
-- Note: text box text has a tendency to shift 1 pixels in some instances in comparison to corona text. You may want to use non-bold font for the text object to compensate for this.  

This source code has been cut out from a larger program, so there may be typos. Please also note that the cursor will move to the end of the field if you edit the textbox text during typing (like removing non-allowed characters or alike).

Anyway, hope it helps someone!

Best,
Renato
Microingress Ltd [import]uid: 141323 topic_id: 24285 reply_id: 137502[/import]

[censored] unsubscribe for this thread on this site doesn’t work!!!
[import]uid: 81188 topic_id: 24285 reply_id: 137538[/import]

I’m sorry this is frustrating you @jkrassman. Can you tell me the steps you are doing to unsubscribe? I’ll see what I can do to help.

Also if it’s not too much to ask, keep in mind we do have younger forum members and if you could avoid profanity, it would be greatly appreciated.

[import]uid: 199310 topic_id: 24285 reply_id: 137559[/import]

Renato,

Thanks for publishing the code but it actually highlights my second biggest frustration with the Corona platform – everything is so iOS oriented. For instance, in many of the replies on this forum, the first answer will often provide an answer which only works on the xCode or iOS simulator but not on Windows. I don’t want to start a battle over which is better but I do expect a commercial tool to provide proper support for the platform I choose to operate in. If Corona were open-source, the situation would be different.

I did manage to create a workaround to the textInput issue which would be acceptable with just a few more tweaks. It automatically creates a native textInput off screen which is tied to a Widget Candy textbox for the UI. It includes a property which allows you to specify an amount to offset the y position when the on-screen keyboard is displayed. Actually, it allows you to specify what group should be moved. It then handles the keyboard events from the native textInput and changes the WidgetCandy text to match. When executed from the simulator, it simply moves group and waits for input.

This all works and, if that were the only issue, I would probably go ahead and commit to Corona. I am, however, very concerned that other issues will come up which might not be so easy to get around. If I were making nothing but games, Corona would be my first choice. For other types of applications, it simply not a suitable tool. Personally, I plan to keep an eye on it’s development and hopefully Ansca will decide to actually update the tool to better support a Windows development environment and creating non-game related applications. I’ve evaluated almost every cross-platform development tool I could find and have decided that Adobe Air using as3 and Starling/Feathers best meets my requirements.

If anyone is interested in the textInput code mentioned above, let me know. Just keep in mind it was created by a complete Conrona noobie and there’s no way I can support it (since I won’t be using Corona). [import]uid: 156068 topic_id: 24285 reply_id: 137629[/import]

maxapps - Thank you for posting and the feedback. Would you mind if I email you directly in order to ask a few questions and get some feedback on how we can improve this? This is an important area for us and we intend to improve here.
David [import]uid: 10668 topic_id: 24285 reply_id: 137648[/import]

My 2 cents as a new Corona developer: I don’t see anything on the roadmap related to fixing the Windows simulator issue, and it concerns me.

I’d love to use Corona for both business apps and games, but I’m in the same boat as some of the others above (no Mac at work). Building and deploying to the device after every code change is obviously not a viable option. [import]uid: 207504 topic_id: 24285 reply_id: 140337[/import]

This is a problem for me too. I need to allow users to enter email addresses, so I’m using the “email” keyboard, but it has caps on by default. I would think it’s rare to want to capitalize your email addresses – and in my case, it’s a real problem. Any workaround? Can you simulate a “shift-key-pressed” event in the textListener function (event.phase == “began”)?

Please let me know if/how others have gotten around this. Do I have to use a 3rd-party keyboard library? Ideally, there would be an optional flag to control the caps state when invoking any keyboard. Also, how about a “.com” key? Thanks! [import]uid: 101071 topic_id: 24285 reply_id: 140472[/import]

@curjo, goto http://feedback.coronalabs.com and enter the request there then vote for it. I’m pretty sure it’s something we are looking at, but putting it there and getting some votes on it will help make sure it gets on the radar.

[import]uid: 199310 topic_id: 24285 reply_id: 140484[/import]

@curjo,

If the problem is the user enters the address in all caps, why can’t you just convert the text back to lowercase afterwards?

local text = string.lower( textField.text )  

The keyboards used in native.newTextField and native.newTextBox are the ones provided by the OS so any feature requests would need to be properties supported by the OS.

You can create your own text input and keyboard entirely in Corona and then you would have full control of what happens. [import]uid: 7559 topic_id: 24285 reply_id: 140538[/import]

Hi Tom:

Thanks for the reply. The problem is not that I want the user to enter in all caps, I want to allow them to enter in lower case (which is how most email addresses are typed) – or in mixed case, if they prefer. The problem is that, while I could force the case to upper or lower after they enter it, this would mean that I’m not storing what they entered (which I need to do). I’d like to simply have it start out defaulted to lower case (i.e., no auto-capitalization) – as this is by far the most typical way addresses will be entered.

Regarding the native OS, there is a property that should be settable to define capitalization. Here is an excerpt from the reference (I’m wanting “UITextAutocapitalizationTypeNone”):

UITextAutocapitalizationType

The auto-capitalization behavior of a text-based view.

typedef enum {  
 UITextAutocapitalizationTypeNone,  
 UITextAutocapitalizationTypeWords,  
 UITextAutocapitalizationTypeSentences,  
 UITextAutocapitalizationTypeAllCharacters,  
} UITextAutocapitalizationType;  

Constants

UITextAutocapitalizationTypeNone
Do not capitalize any text automatically.
Available in iOS 2.0 and later.
Declared in UITextInputTraits.h.

UITextAutocapitalizationTypeWords
Capitalize the first letter of each word automatically.
Available in iOS 2.0 and later.
Declared in UITextInputTraits.h.

UITextAutocapitalizationTypeSentences
Capitalize the first letter of each sentence automatically.
Available in iOS 2.0 and later.
Declared in UITextInputTraits.h.

UITextAutocapitalizationTypeAllCharacters
Capitalize all characters automatically.
Available in iOS 2.0 and later.
Declared in UITextInputTraits.h. [import]uid: 101071 topic_id: 24285 reply_id: 140546[/import]

You can create your own text input and keyboard entirely in Corona and then you would have full control of what happens.

This is certainly possible and I did entertain the idea for a couple minutes. It might even be doable for entering text into one or maybe two fields. My contention was that Corona is being touted as a viable platform for creating non-gaming apps which is simply not true when there is such limited support for something so basic as entering text via the native keyboard. I just can’t see a serious business app requiring the user to enter text into multiple fields using a Corona created, app-specific keyboard. I don’t think Apple users would want to give up the iOS keyboard and it’s worse on Android where many of us have picked a specific 3rd party keyboard because we find it easier to use.

Personally, I’m still hoping Corona builds a usable Windows simulator and does something to fix the TextInput issue. I seem to be in the minority, though, because there didn’t seem to be much support for either according to votes on the Future Feature page. This seems to reinforce the notions that:
a) Corona is mainly used to create games and,
b) Corona is used mainly by Apple developers

At the moment, I’m trying out Flash/AIR with Starling/Feathers. Text support isn’t quite as good as with Flex but it’s vastly better than Corona and the scrolling speed and animations are very, very smooth. The windows mobile simulator seems to be pretty good and on-device debugging works as expected. The biggest drawback is the load times because adding AIR to the app makes it very large. Not adding AIR means it has to already be on the user’s device.
[import]uid: 156068 topic_id: 24285 reply_id: 140582[/import]

@maxapps, can you explain what you mean by this:

“My contention was that Corona is being touted as a viable platform for creating non-gaming apps which is simply not true when there is such limited support for something so basic as entering text via the native keyboard.”

Is this just a matter of giving more access to keyboard properties? [import]uid: 26 topic_id: 24285 reply_id: 140674[/import]