native.newTextField

@renato.bugge

It works but does not return the right value, I discovered this while working with textfields. I found a utf8 library that takes care of string.len() but not string.upper/lower().

If you would create text edit app and would want to know the character count len() would not return the correct count, however bytewise it is correct.

Run this.

local txt1 = "åäöÅÄÖ" -- len return 12, string.upper/lower() does not work.  
local txt2 = "abcABC" -- len return 6, string.upper/lower() does work.  
  
local lower = display.newText("txt1 (åäöÅÄÖ) to Lower: "..string.lower(txt1), 30, 150, 260, 0, "Helvetica", 16)  
local upper = display.newText("txt2 (abcABC) to Upper "..string.upper(txt2), 30, 190, 260, 0, "Helvetica", 16)  
local len = display.newText("txt1 Len: "..string.len(txt1).."\ntxt2 Len: "..string.len(txt2), 30, 230, 260, 0, "Helvetica", 16)  
  

Utf8 functions from the lib that fix the len() issue.

[code]
function utf8charbytes (s, i)
– argument defaults
i = i or 1
local c = string.byte(s, i)

– determine bytes needed for character, based on RFC 3629
if c > 0 and c <= 127 then
– UTF8-1
return 1
elseif c >= 194 and c <= 223 then
– UTF8-2
local c2 = string.byte(s, i + 1)
return 2
elseif c >= 224 and c <= 239 then
– UTF8-3
local c2 = s:byte(i + 1)
local c3 = s:byte(i + 2)
return 3
elseif c >= 240 and c <= 244 then
– UTF8-4
local c2 = s:byte(i + 1)
local c3 = s:byte(i + 2)
local c4 = s:byte(i + 3)
return 4
end
end
– returns the number of characters in a UTF-8 string
function utf8len (s)
local pos = 1
local bytes = string.len(s)
local len = 0

while pos <= bytes and len ~= chars do
local c = string.byte(s,pos)
len = len + 1

pos = pos + utf8charbytes(s, pos)
end

if chars ~= nil then
return pos - 1
end

return len
end
[/code] [import]uid: 13560 topic_id: 24285 reply_id: 141530[/import]

The native textfield creates illegible textfields on a Samsung Galaxy.

I have tested on an Ainol and an Iphone, and it is usable, but on said Samsung the user would have no idea what text they have entered (other than what they thought they typed) and certainly no way of verifying.

[import]uid: 118305 topic_id: 24285 reply_id: 142230[/import]

Just curious, when I use the fieldlistener for multiple fields in the api section, how do I return each fields text?

The example show getObj().text, if I have three fields ( field1, field2…etc) how do I save that text in a variable?

If I just have one field with a single listener then I would just do;

fieldString = field1.text

and save that a file or a table etc. How to does it work with multi-fieldlistener?

Thanks
C.

[import]uid: 65840 topic_id: 24285 reply_id: 142233[/import]

Is there a plan in place to support keyboard options. For example on iOS devices you can set in your settings the ability to
* Auto-Capitalization
* Auto-Correction
* Check Spelling

But in your app, you can modify the default settings of the app. For example, if you don’t want the app to check for spelling or to auto-correct, etc.

The reason I ask is because I am building a spelling app and it is useless to use your keyboard if it continually pops up spelling suggestions.

I have written a keyboard from scratch but there are so many issues like supporting different languages, supporting right-to-left languages etc that I’d rather use the native keyboards if possible instead of doing all the language support.
[import]uid: 138352 topic_id: 24285 reply_id: 141774[/import]

The best way to bump up the feature is go to our feedback page and add/vote on the feature.
http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback [import]uid: 7559 topic_id: 24285 reply_id: 141813[/import]

I solved the upper/lower case issue with mapping, writing a routine was just to much hazzle atm. I only need to map 6 characters (åäöÅÄÖ) so it was easy and fast. [import]uid: 13560 topic_id: 24285 reply_id: 141842[/import]

Actually, you are right in a way:

for l=1,3 do  
print(string.sub("abc",l,l))  
end  

prints:
a
b
c

but using

for l=1,3 do  
print(string.sub("æøå",l,l))  
end  

result in an error:
2013-02-06 12:50:19.493 Corona Simulator[19598:f07] Generic error:
2013-02-06 12:50:19.493 Corona Simulator[19598:f07] NSInvalidArgumentException: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil

(plus alot of garbage output)

But, assuming this is a character coding scheme in which ø is actually two characters
(like unicode o/slash/):

for l=1,3 do  
print(string.sub("æøå",l\*2-1,l\*2))  
end  

actually prints:
æ
ø
å

So it seems like the length of special characters in some instances are 2 bytes. When this happends, trying to get a substring which is only half the character (string.sub(“æ”,1,1)) results in a simulator crash. If you always treat the character as two bytes, it works with minor problems…
[import]uid: 141323 topic_id: 24285 reply_id: 141847[/import]

The native textfield creates illegible textfields on a Samsung Galaxy.

I have tested on an Ainol and an Iphone, and it is usable, but on said Samsung the user would have no idea what text they have entered (other than what they thought they typed) and certainly no way of verifying.

[import]uid: 118305 topic_id: 24285 reply_id: 142230[/import]

Just curious, when I use the fieldlistener for multiple fields in the api section, how do I return each fields text?

The example show getObj().text, if I have three fields ( field1, field2…etc) how do I save that text in a variable?

If I just have one field with a single listener then I would just do;

fieldString = field1.text

and save that a file or a table etc. How to does it work with multi-fieldlistener?

Thanks
C.

[import]uid: 65840 topic_id: 24285 reply_id: 142233[/import]

can Corona supply the old email keyboard for people who want all cap entry since it has already been worked out? maybe just rename it all caps? it would be very helpful for name input fields where descenders force you to reduce the size of the font.

also, is there a way to get the first line of a scrolling text box to return to its original position when you reenter a scene? THANKS!

can Corona supply the old email keyboard for people who want all cap entry since it has already been worked out? maybe just rename it all caps? it would be very helpful for name input fields where descenders force you to reduce the size of the font.

also, is there a way to get the first line of a scrolling text box to return to its original position when you reenter a scene? THANKS!