HI,
what I want to accomplish is when I create a native.newTextField set the isSecure option to false and the placeholder to “type your password”
and whenever a user start typing, change the textfield to isSecure = true, to have the * symbols.
with my approach I have the problem that my textfield lose focus after the first letter.
here is my code:
local function fieldHandler( event ) if ( "began" == event.phase ) then -- This is the "keyboard has appeared" event -- In some cases you may want to adjust the interface when the keyboard appears. elseif ( "ended" == event.phase ) then -- This event is called when the user stops editing a field: for example, when they touch a different field if(event.target.id == "password" and event.target.text == "")then event.target.isSecure = false passwordField.placeholder = "type your password" end elseif ( "editing" == event.phase ) then if(event.target.id == "password" and string.len(event.target.text) \>0 ) then event.target.isSecure = true --native.setKeyboardFocus( event.target ) end elseif ( "submitted" == event.phase ) then -- Hide keyboard native.setKeyboardFocus( nil ) end end
–scene:show
–Did
local passwordField = native.newTextField( \_CX - fieldWidth/2, passwordFieldBg.y, fieldWidth, 40 ) passwordField.id = "password" passwordField:addEventListener( "userInput", fieldHandler ) group:insert( passwordField) passwordField.hasBackground = false passwordField.anchorX = 0 passwordField.placeholder = "type your password" passwordField.autocorrectionType = "UITextAutocorrectionTypeNo" passwordField.isSecure = false passwordField.font = native.newFont( gM.fontDin ) passwordField:resizeFontToFitHeight()
please help me to solve this, or another approach that I could use.
thanks,
Version 2016.2883 (2016.5.17)