Switching between display groups with newTextField

Hi,

I am making a login/register scene and so I made 2 display groups:

function scene:create(event) -- New player display group newPlayerGroup = display.newGroup(); sceneGroup:insert(newPlayerGroup); createUsernameField = native.newTextField(options) newPlayerGroup:insert(createUsernameField) -- Login display group loginGroup = display.newGroup(); sceneGroup:insert(loginGroup); loginUsernameField = native.newTextField(options) loginGroup:insert(loginUsernameField) loginPasswordField = native.newTextField(options) loginGroup:insert(loginPasswordField) end

Then I set  loginGroup.isVisible = false on scene:show.

I also use two widget.newButton to call a function that toggles the visibility of the display groups but the textFields are always visible once they’re shown.

Should I use object:removeSelf() on the textFields?

How do I get the textFields to show/hide accordingly?

Thanks in advance!

Look at this project:

https://github.com/coronalabs-samples/business-app-sample

It should have examples of handling input fields in scenes.  This one also has some additional form handling techniques:

https://github.com/coronalabs-samples/CoronaWeather

Rob

Hi Rob,

How come those example use the fieldHandler function with a return like so:

firstNameField:addEventListener( "userInput", fieldHandler( function() return firstNameField end ) )

and

-- handle the user input --local hasFetchedLocationList = false local function fieldHandler( textField ) return function( event ) print( event.phase, textField().text ) if ( "began" == event.phase ) then elseif ( "ended" == event.phase ) then elseif ( "editing" == event.phase ) then end end end

Instead of the way shown in the newTextField documentation where they just call the function with no returns anywhere. Is it needed? I implemented my textFields without the “return method” and it works fine.

There are multiple ways to handle text fields. The method used in those is useful when using multiple text fields and a singular processing function.

Rob

Look at this project:

https://github.com/coronalabs-samples/business-app-sample

It should have examples of handling input fields in scenes.  This one also has some additional form handling techniques:

https://github.com/coronalabs-samples/CoronaWeather

Rob

Hi Rob,

How come those example use the fieldHandler function with a return like so:

firstNameField:addEventListener( "userInput", fieldHandler( function() return firstNameField end ) )

and

-- handle the user input --local hasFetchedLocationList = false local function fieldHandler( textField ) return function( event ) print( event.phase, textField().text ) if ( "began" == event.phase ) then elseif ( "ended" == event.phase ) then elseif ( "editing" == event.phase ) then end end end

Instead of the way shown in the newTextField documentation where they just call the function with no returns anywhere. Is it needed? I implemented my textFields without the “return method” and it works fine.

There are multiple ways to handle text fields. The method used in those is useful when using multiple text fields and a singular processing function.

Rob