It takes only a few lines to acomplish auto-capitalization. There are bigger problems in native.newTextBox and native.newTextField. Position is way bigger problem that was never resolved.
i’ve made my own code to resolve that, and as a bonus i’ve put the autocap inside:
----------------------------------------------------------------------------------------- -- -- creates a newTextBox with a label -- v1.02 02/10/2015 \* i've made some changes since my inicial post -- -- params: -- label (default: "label:") -- labelAlign (default: "left") -- labelFont (default: native.systemFont) -- labelFontSize (default: 14) -- labelDistance (default: 0) -- labelWidth (default: 200) -- labelColor (default: {1,1,1}) -- textFont (default: native.systemFont) -- textFontSize (default: 12) -- x (default: 0) -- y (default: 0) -- width (default: 200) -- height (default: 100) -- anchorX (default: 0.5) -- anchorY (default: 0.5) -- textColor (default: {0,0,0}) -- -- bonus params: -- allCaps - true/false (default is false) -- minChars - 0 - \* (default is 0) -- maxChars - 1 - \* (default is 1000) ----------------------------------------------------------------------------------------- -- Your code here local centerX=display.contentWidth\*.5 local centerY=display.contentHeight\*.5 local function RGB (cor) -- faster than unpack local c = cor or {1,1,1,1} local r = c[1] or 1 local g = c[2] or 1 local b = c[3] or 1 local a = c[4] or 1 return r, g, b, a end local function newTextBox(paramsIn) local params=paramsIn local group=display.newGroup() local label=params.label or "label:" local labelAlign=params.labelAlign or "left" local labelFont=params.labelFont or native.systemFont local labelFontSize=params.labelFontSize or 14 local labelDistance=params.labelDistance or 0 local labelWidth=params.labelWidth or 200 local labelColor=params.labelColor or {1,1,1} local textFont=params.textFont or native.systemFont local textFontSize=params.textFontSize or 12 local textColor=params.textColor or {0,0,0} local text=params.text or "insert your text here." local x=params.x or 0 local y=params.y or 0 local width=params.width or 200 local height=params.height or 100 local minChars=math.abs(params.minChars) or 0 local maxChars=params.maxChars or 1000 if maxChars \<=0 then maxChars=1 end if minChars\>=maxChars then minChars=maxChars-1 end local anchorX=params.anchorX or 0.5 local anchorY=params.anchorY or 0.5 local allCaps=params.allCaps or false local flag=false local textBox local firstTime=true local function inputListener( event ) if event.phase == "began" and firstTime then text="" event.target.text="" firstTime=false elseif event.phase == "ended" or event.phase == "submitted" then text=event.target.text native.setKeyboardFocus(nil) elseif event.phase == "editing" then local tempString if allCaps then local capLetter=string.upper(event.target.text) tempString=""..capLetter event.target.text=capLetter else tempString=""..event.target.text end if string.len(tempString)\>=minChars and string.len(tempString)\<=maxChars then flag=true else flag=false end if (string.len(tempString)\> maxChars) then event.target.text = event.oldText textBox.text=event.oldText text = event.oldText flag=true native.setKeyboardFocus(nil) else text = event.target.text end end group.flag=flag group.text=text end local params={ text=label, align=labelAlign, font=labelFont, fontSize=labelFontSize, width=labelWidth, x=x, y=y, } local labelG=display.newText(params) ----------------------- calculating position of label, text and anchors before it creats to avoid native.newTextBox slow render ------------------------ local heightTotal=height+labelG.contentHeight+labelDistance local addX=width-(width\*anchorX)-width\*.5 local addY=heightTotal-(heightTotal\*anchorY)-heightTotal\*.5 labelG.x=x+addX labelG.y=y+addY-heightTotal\*.5+labelG.contentHeight\*.5 labelG:setFillColor(RGB(labelColor)) group:insert(labelG) local newX=x+addX local newY=labelG.y+labelG.contentHeight\*.5+labelDistance+height\*.5 textBox = native.newTextBox( newX, newY, width, height ) textBox:setTextColor(RGB(textColor)) textBox.text = text textBox.isEditable = true textBox.font = native.newFont( textFont, textFontSize ) textBox:addEventListener( "userInput", inputListener ) group:insert(textBox) group.label=label group.text=text group.flag=flag return group end -------------------------------------------- main code ----------------- local params={ label="Name:", labelAlign="left", labelFont="Arial", labelFontSize=14, labelDistance=0, labelWidth=200, labelColor={1,1,0}, textFontSize=12, x=centerX, y=centerY, width=200, height=50, minChars=3, maxChars=10, anchorX=0.5, anchorY=0.5, textColor={0,0,0}, allCaps=false } local obj=newTextBox(params) -- obj.x=obj.x+50 -- obj.y=obj.y+50 ----------------------------------- button to check if box input is ok! local widget = require( "widget" ) local warning local function handleButtonEvent( event ) if ( "ended" == event.phase ) then local params if obj.flag then params={ text="Correct Input!", } else params={ text="Invalid Input!\nMin input is 3 chars.\nMax input is 10 chars.", } end params.fontSize=12 params.width=200 params.align="center" if warning then display.remove(warning) warning=nil end warning=display.newText(params) warning:setFillColor(1,0,0) warning.x=centerX warning.y=centerY+100 end end local button1 = widget.newButton { left = 50, top = display.contentHeight-50, id = "button1", label = "Check Box", onEvent = handleButtonEvent }
you can test it and change it as you like.