Text field issue

Hello,

I have been developing an app called Espoir as a part of my college project, where you can take pictures, select your location and upload complaints like bad roads, garbage issues etc.

There is the 1st page which consists of a registration button. On you clicking the registration button, you enter page 2a, where you enter your details and confirm.

After you confirm you are directed to another page that is page 3, but there seems to be a problem while page 3 is being displayed. The page seems to shift to the right side of the screen and only half of the screen is visible.

Whenever i remove page 2a and connect all the other pages, it seems to be fine. Only when i connect 2a in-between , which consists of text boxes, this problem occurs.The problem occurs on all the pages that follow page 2a.

I have tried to resolve this issue since a week and have not been able to figure it out. Could you please help me.

i have provided the screenshots of output and also the .txt files of the code.

The order is as follows:

main->page1->page2a->page3->page4



– main.lua


– hide the status bar

display.setStatusBar( display.HiddenStatusBar )

– require the composer library

local composer = require “composer”

composer.gotoScene( “page1” )

local widget = require( “widget” )

local json = require( “json” )

local myApp = require( “myapp” ) 

– Initialize database

local db = require( “database” )

local myScheme = {}

myScheme["__tableName"] = “User_details”

myScheme[“user_id”] = “text”

myScheme[“user_name”] = “text”

myScheme[“user_phno”] = “text”

myScheme[“user_emailid”] = “text”

– Create the database

– Store the object handle in global myApp table

myScheme["__tableName"] = “User_contact”

myScheme[“user_id”] = “text”

myScheme[“user_phno”] = “text”

db.init( “espoir.db”, myScheme )

myScheme["__tableName"] = “Complaint_details”

myScheme[“complaint_id”] = “text”

myScheme[“complaint_description”] = “text”

myScheme[“c_area”] = “text”

myScheme[“c_street”] = “text”

myScheme[“c_city”] = “text”

myScheme[“c_date”] = “text”

myScheme[“c_month”] = “text”

myScheme[“c_year”] = “text”

myScheme[“c_image”] = “text”

myScheme[“c_status”] = “text”

–myScheme[“c_count”] = “text”

myScheme[“user_id”] = “text”

myScheme[“category_id”] = “text”

db.init( “espoir.db”, myScheme )

myScheme["__tableName"] = “Category_details”

myScheme[“category_id”] = “text”

myScheme[“category_name”] = “text”

myScheme[“department_id”] = “text”

db.init( “espoir.db”, myScheme )

myScheme["__tableName"] = “Department_details”

myScheme[“department_id”] = “text”

myScheme[“category_id”] = “text”

myScheme[“department_name”] = “text”

db.init( “espoir.db”, myScheme )

myScheme["__tableName"] = “Officer_details”

myScheme[“officer_id”] = “text”

myScheme[“officer_phone”] = “text”

db.init( “espoir.db”, myScheme )

myScheme["__tableName"] = “Office_details”

myScheme[“officer_id”] = “text”

myScheme[“department_id”] = “text”

myScheme[“officer_name”]=“text”

myScheme[“officer_mailid”]=“text”

myScheme[“officer_phone”] = “text”

db.init( “espoir.db”, myScheme )


page1.lua


local composer = require (“composer” )

local scene = composer.newScene()

local widget = require( “widget” )

function scene:create( event )

    local sceneGroup = self.view

   

    display.setStatusBar( display.HiddenStatusBar ) 

    display.setDefault( “background”, 1 )

    local titleString = “Espoir”

    local LEFT_PADDING = 10

    local halfW = display.contentCenterX

    local halfH = display.contentCenterY

    local width = display.actualContentWidth

    local supportHPS = system.getInfo( “gpuSupportsHighPrecisionFragmentShaders” )

    local titleBar = display.newRect( sceneGroup, halfW, 0, width, 38 )

    titleBar.fill = { type = ‘gradient’, color1 = { .75, .8, .86, 1 }, color2 = { 0, 0.56, 1, 1 } }

    titleBar.y = display.screenOriginY + titleBar.contentHeight * 0.5

    local titleText = display.newEmbossedText( sceneGroup, titleString , halfW, titleBar.y, native.systemFontBold, 20 )

    local myText1 = display.newText( “Hello!!”, display.contentCenterX, display.contentWidth / 3, native.systemFont, 32 )

    myText1:setFillColor( 1, 0.3 , 0)

    sceneGroup:insert(myText1)

    local myText2 = display.newText( “Welcome to ESPOIR”, display.contentCenterX, display.contentWidth / 2, native.systemFont, 32 )

    myText2:setFillColor( 1, 0.3 , 0)

    sceneGroup:insert(myText2)

    local myText = display.newText( “(If Registered then Login)”, 160,410, native.systemFont, 12 )

myText:setFillColor( 1, 0.3, 0)

    sceneGroup:insert(myText)

    local function button1Press() 

   composer.gotoScene( “page2a”, “fade”)

    end

    local function button2Press() 

     composer.gotoScene( “page2b”, “fade”)

    end

  local button1 = widget.newButton

  {

id = “button1”,

width=280,

  height=40,

defaultFile = “buttonBlue.png”,

overFile = “buttonBlueOver.png”,

label = “REGISTER”,

labelColor = 

default = { 51, 51, 51, 255 },

},

font = native.systemFont,

fontSize = 18,

emboss = false,

    onPress = button1Press,

}

local button2 = widget.newButton

{

id = “button2”,

        width=280,

  height=40,

defaultFile = “buttonBlue.png”,

overFile = “buttonBlueOver.png”,

label = “LOGIN”,

labelColor = 

default = { 51, 51, 51, 255 },

},

font = native.systemFont,

fontSize = 18,

emboss = false,

onPress = button2Press,

}

button1.x = 160; button1.y = 300

button2.x = 160; button2.y = 375

sceneGroup:insert(button1)

    sceneGroup:insert(button2)

end

function scene:show( event )

    local sceneGroup = self.view

    local phase = event.phase

    if phase == “will” then

        – Called when the scene is still off screen and is about to move on screen

       

    elseif phase == “did” then

        – Called when the scene is now on screen

        end

        

    end 

– buttons

function scene:hide( event )

    local sceneGroup = self.view

    local phase = event.phase

    if event.phase == “will” then

        – Called when the scene is on screen and is about to move off screen

        –

        – INSERT code here to pause the scene

        – e.g. stop timers, stop animation, unload sounds, etc.)

    elseif phase == “did” then

        – Called when the scene is now off screen

end

    end 

function scene:destroy( event )

    local sceneGroup = self.view

    – Called prior to the removal of scene’s “view” (sceneGroup)

    – 

    – INSERT code here to cleanup the scene

    – e.g. remove display objects, remove touch listeners, save state, etc

end


– Listener setup

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene


page2a.lua


local composer = require (“composer” )

local scene = composer.newScene()

–local String = require(“string”)

local widget = require( “widget” )

local myApp = require( “myapp” )

local db = require( “database” 

)

local defaultField, numberField, phoneField, urlField, emailField, passwordField

local number1, test_password,number

local test_id,testpwd

local id=0

local count=0

local pwd=0

local test_id1,testpwd1

 local record = {}

local results={}

local results1={}

local a={}

local strbyte1={}

local strbyte2={}

local strstrbyte3,strbyte4

– You could also assign different handlers for each textfield

local function fieldHandler( textField )

return function( 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

elseif ( “editing” == event.phase ) then

elseif ( “submitted” == event.phase ) then

– This event occurs when the user presses the “return” key (if available) on the onscreen keyboard

print( textField().text )

– Hide keyboard

native.setKeyboardFocus( nil )

end

end

end

function scene:create( event )

    local sceneGroup = self.view

    display.setStatusBar( display.HiddenStatusBar ) 

    display.setDefault( “background”, 1 )

local titleString = “Espoir”

local LEFT_PADDING = 10

local halfW = display.contentCenterX

local halfH = display.contentCenterY

local width = display.actualContentWidth

local supportHPS = system.getInfo( “gpuSupportsHighPrecisionFragmentShaders” )

    local titleBar = display.newRect( sceneGroup, halfW, 0, width, 38 )

    titleBar.fill = { type = ‘gradient’, color1 = { .75, .8, .86, 1 }, color2 = { 0, 0.56, 1, 1 } }

    titleBar.y = display.screenOriginY + titleBar.contentHeight * 0.5

– create embossed text to go on toolbar

    local titleText = display.newEmbossedText( sceneGroup, titleString , halfW, titleBar.y, native.systemFontBold, 20 )

display.setDefault( “anchorX”, 0.0 ) – default to TopLeft anchor point for new objects

display.setDefault( “anchorY”, 0.0 )

local defaultLabel = display.newText( sceneGroup,“NAME”, 10, 65, native.systemFont, 15 )

defaultLabel:setFillColor( 0, 0, 0, 1)

local defaultLabel = display.newText( sceneGroup,“EMAIL ID”,15, 129, native.systemFont, 15 )

defaultLabel:setFillColor( 0, 0, 0, 1)

local defaultLabel = display.newText( sceneGroup,“PHONE NUMBER”,15, 193, native.systemFont, 15 )

defaultLabel:setFillColor( 0, 0, 0, 1)

   local function onComplete( event )

          if “clicked” == event.action then

                local i = event.index

                if 1 == i then

print ‘OK’

composer.gotoScene(“page3”,“fade”)

elseif “cancelled” == event.action then

– our cancelAlert timer function dismissed the alert so do nothing

        end   

    end

end

   local function onComplete1( event )

          if “clicked” == event.action then

              

     

elseif “cancelled” == event.action then

– our cancelAlert timer function dismissed the alert so do nothing

        end   

    end

 local function testid()

print(“testid called”)

number1=math.random(1,9)* math.random(1,9)*math.random(1,7)

test_id=“1EP” … number1

test_id=tostring(test_id)

    print(“generated id”…test_id)

    results = db.read(‘SELECT user_id FROM  User_details ;’)

    local len1= string.len(test_id)

local len2

print (len1)

–strbyte1=string.byte(test_id ,1, len1 )

–for i=0, len1 do

–print(strbyte1[i])

–end

local resultstring

for i=1, #results do

print(" db value"…results[i].user_id)

resultstring=results[i].user_id

resultstring=tostring(resultstring)

print(resultstring)

     len2=string.len(resultstring)

     local j=i

 print(len2)

 if len1==len2 then

   print(" length equal and hence if enterd")

        count=0  

  for i=1, len1 do

  

     strbyte1[i]=string.byte(test_id ,i )

     strbyte2[i]= string.byte(resultstring,i)

end

for i=1, len1 do

   

       if strbyte1[i]==strbyte2[i] then

             print (strbyte1[i])

 print (strbyte1[i])

      count=count+1

end

end 

if count == len1 then

        –  number1=math.random(1,9)* math.random(1,9)*math.random(1,7)

             print (“both match”)    

testid()

      

      end

  end

     end

print(" doesnt match any values in db")

  record.user_id= test_id

  end

local function passwordgenerate()

     print (“password generate called”)

     local str=“ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”

for i = 1, 4, 1 do

  a[i]= string.char(str:byte(math.random(1, #str)))

     end

number=math.random(1,9)* math.random(1,9)*math.random(1,7)

     testpwd=“P”

for i = 1, 4, 1 do

     testpwd = testpwd…a[i]

end

testpwd=testpwd…number

testpwd=tostring(testpwd)

print(“generated password”…testpwd)

results = db.read(‘SELECT user_password FROM  User_details ;’)

local len1= string.len(testpwd)

local len2

print (len1)

local count=0

local resultstring

for i=1, #results do

print(" db value"…results[i].user_password)

resultstring=results[i].user_password

resultstring=tostring(resultstring)

print(resultstring)

     len2=string.len(resultstring)

     local j=i

 print(len2)

 if len1==len2 then

   print(" length equal and hence if enterd")

count=0

    for i=1, len1 do

  

     strbyte1[i]=string.byte(testpwd ,i )

     strbyte2[i]= string.byte(resultstring,i)

end

for i=1, len1 do

       if strbyte1[i]==strbyte2[i] then

       count=count+1 

end

end

if count == len1 then

        –  number1=math.random(1,9)* math.random(1,9)*math.random(1,7)

             print (“both match”)

    passwordgenerate()

end

end

end

 print(" doesnt match any values in db")

  record.user_password= testpwd

  end

  

   local function submitForm( event )

     if nameField.text == nil or nameField.text=="" or emailField.text == nil or emailField.text== “” or phoneField.text==nil or phoneField.text=="" then 

 local alert2 = native.showAlert( “My Alert Box”, “Fill in all the fields” )

elseif ((emailField.text:match("[A-Za-z0-9%.%%%+%-]+@[A-Za-z0-9%.%%%+%-]+%.%w%w%w?%w?"))== false) then

    print ( " valid email")

    

    local alert3=native.showAlert( “My Alert Box”, “INVAlID EMAIL”,{“OK”}  )               

 else

testid()

passwordgenerate()  

  record.user_name = nameField.text

  record.user_phno = phoneField.text

  record.user_emailid = emailField.text

–  print( json.prettify( record ) )

  db.create( record )

    localalert1 = native.showAlert( “My Alert Box”, “Registration Successfull!!Your userId is —> " …record.user_id… " password —>”… record.user_password, { “OK” }, onComplete )

end    

end

 local button1 = widget.newButton

{

id = “button1”,

width=140,

  height=35,

defaultFile = “buttonBlue.png”,

label = “CONFIRM”,

labelColor = 

default = { 51, 51, 51, 255 },

},

font = native.systemFont,

fontSize = 16,

emboss = false,

onPress = submitForm,

}

  button1.x = 90; button1.y = 275

  sceneGroup:insert(button1)

  nameField = native.newTextField( 23, 88, 275, 25)

–nameField.inputType = “default”

  nameField:addEventListener( “userInput”, fieldHandler( function() return nameField end ) ) 

  sceneGroup:insert(nameField)

  emailField = native.newTextField( 23,150, 275, 25)

  --emailField.inputType = “email”

  emailField:addEventListener( “userInput”, fieldHandler( function() return emailField end ) ) 

  sceneGroup:insert(emailField)

  phoneField = native.newTextField( 23,212, 275, 25)

  phoneField.inputType = “number”

  phoneField:addEventListener( “userInput”, fieldHandler( function() return phoneField end ) ) 

  sceneGroup:insert(phoneField)

end

function scene:show( event )

local sceneGroup = self.view

local phase = event.phase

if phase == “will” then

elseif ( phase == “did” ) then

end

end

function scene:hide( event )

    local sceneGroup = self.view

    local phase = event.phase

    if event.phase == “will” then

    

  

    elseif phase == “did” then

        – Called when the scene is now off screen

end

   end

function scene:destroy( event )

    local sceneGroup = self.view

–field.display()

    – Called prior to the removal of scene’s “view” (sceneGroup)

    – 

    – INSERT code here to cleanup the scene

    – e.g. remove display objects, remove touch listeners, save state, etc

end


– Listener setup

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene

----------------------------------------------------------------------------------------------------------------------------------------page3.lua


local composer = require (“composer” )

local scene = composer.newScene()

local widget = require( “widget” )

–local json = require( “json” )

local myApp = require( “myapp” )

local db = require( “database” )

composer.removeScene(“page2a”)

function scene:create( event )

composer.removeScene( “page2a” )

    local sceneGroup = self.view

display.setStatusBar( display.HiddenStatusBar ) 

    display.setDefault( “background”, 1 )

    local titleString = “Espoir”

    – create a constant for the left spacing of the row content

    local LEFT_PADDING = 10

    local halfW = display.contentCenterX

    local halfH = display.contentCenterY

    local width = display.actualContentWidth

local supportHPS = system.getInfo( “gpuSupportsHighPrecisionFragmentShaders” )

    local titleBar = display.newRect( sceneGroup, halfW, 0, width, 38 )

    titleBar.fill = { type = ‘gradient’, color1 = { .75, .8, .86, 1 }, color2 = { 0, 0.56, 1, 1 } }

    titleBar.y = display.screenOriginY + titleBar.contentHeight * 0.5

    local titleText = display.newEmbossedText( sceneGroup, titleString , halfW, titleBar.y, native.systemFontBold, 20 )

    local function button1Press() 

         composer.gotoScene( “category”, “fade”)

    end

    local function button2Press() 

         composer.gotoScene( “my_complaints”, “fade”)

   end

    – create embossed text to go on toolbar

    button1 = widget.newButton

    {

  id = “button1”,

  width=280,

    height=40,

  defaultFile = “buttonBlue.png”,

  overFile = “buttonBlueOver.png”,

  label = “Place a Complaint”,

  labelColor = 

  { 

default = { 51, 51, 51, 255 },

       },

  font = native.systemFont,

  fontSize = 18,

  emboss = false,

  onPress = button1Press,

    }

    button2 = widget.newButton

   {

  id = “button2”,

       width=280,

    height=40,

  defaultFile = “buttonBlue.png”,

  overFile = “buttonBlueOver.png”,

  label = “My Complaints”,

  labelColor = 

  { 

default = { 51, 51, 51, 255 },

  },

  font = native.systemFont,

  fontSize = 18,

  emboss = false,

  onPress = button2Press,

    }

    

button1.x = 160; button1.y = 390

    button2.x = 160; button2.y = 440

sceneGroup:insert(button1)

    sceneGroup:insert(button2)

end

function scene:show( event )

composer.removeScene( “page2a” )

    local sceneGroup = self.view

    local phase = event.phase

    if phase == “will” then

        – Called when the scene is still off screen and is about to move on screen

       

    elseif phase == “did” then

        – Called when the scene is now on screen

        end

        

    end 

– buttons

function scene:hide( event )

    local sceneGroup = self.view

    local phase = event.phase

    if event.phase == “will” then

        – Called when the scene is on screen and is about to move off screen

        –

        – INSERT code here to pause the scene

        – e.g. stop timers, stop animation, unload sounds, etc.)

    elseif phase == “did” then

        – Called when the scene is now off screen

end

    end 

function scene:destroy( event )

    local sceneGroup = self.view

    – Called prior to the removal of scene’s “view” (sceneGroup)

    – 

    – INSERT code here to cleanup the scene

    – e.g. remove display objects, remove touch listeners, save state, etc

end


– Listener setup

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene


page4.lua


– 

– Abstract: GeneratorViewer sample app

–  

– Version: 2.0

– 

– Sample code is MIT licensed, see https://www.coronalabs.com/links/code/license

– Copyright © 2013 Corona Labs Inc. All Rights Reserved.

– Supports Graphics 2.0


local composer = require (“composer” )

local scene = composer.newScene()

local widget = require( “widget” )

local json = require( “json” )

local myApp = require( “myapp” )

local db = require( “database” )

function scene:create( event )

    local sceneGroup = self.view

display.setDefault( “background”, 1 )

local titleString = “Espoir”

local LEFT_PADDING = 10

local halfW = display.contentCenterX

local halfH = display.contentCenterY

local width = display.actualContentWidth

local supportHPS = system.getInfo( “gpuSupportsHighPrecisionFragmentShaders” )

– Create toolbar to go at the top of the screen

local titleBar = display.newRect( sceneGroup, halfW, 0, width, 38 )

titleBar.fill = { type = ‘gradient’, color1 = { .75, .8, .86, 1 }, color2 = { 0, 0.56, 1, 1 } }

titleBar.y = display.screenOriginY + titleBar.contentHeight * 0.5

– create embossed text to go on toolbar

local titleText = display.newEmbossedText( sceneGroup, titleString , halfW, titleBar.y, native.systemFontBold, 20 )

– buttons

local function button1Press() 

    composer.gotoScene( “category”, “fade”)

    end

local function button2Press() 

      composer.gotoScene( “my_complaints”, “fade”)

    end

local button1 = widget.newButton

{

id = “button1”,

width=280,

  height=40,

defaultFile = “buttonBlue.png”,

overFile = “buttonBlueOver.png”,

label = “Place a Complaint”,

labelColor = 

default = { 51, 51, 51, 255 },

},

font = native.systemFont,

fontSize = 18,

emboss = false,

onPress =button1Press ,

}

local button2 = widget.newButton

{

id = “button2”,

        width=280,

  height=40,

defaultFile = “buttonBlue.png”,

overFile = “buttonBlueOver.png”,

label = “My Complaints”,

labelColor = 

default = { 51, 51, 51, 255 },

},

font = native.systemFont,

fontSize = 18,

emboss = false,

onPress=button2Press,

}

button1.x = 160; button1.y = 220

button2.x = 160; button2.y = 280

sceneGroup:insert(button1)

sceneGroup:insert(button2)

end

function scene:show( event )

local sceneGroup = self.view

local phase = event.phase

if ( phase == “will” ) then

– Code here runs when the scene is still off screen (but is about to come on screen)

elseif ( phase == “did” ) then

– Code here runs when the scene is entirely on screen

end

end

function scene:hide( event )

    local sceneGroup = self.view

    local phase = event.phase

    if event.phase == “will” then

        – Called when the scene is on screen and is about to move off screen

        –

        – INSERT code here to pause the scene

        – e.g. stop timers, stop animation, unload sounds, etc.)

    elseif phase == “did” then

        – Called when the scene is now off screen

end

   end

function scene:destroy( event )

    local sceneGroup = self.view

     

    – Called prior to the removal of scene’s “view” (sceneGroup)

    – 

    – INSERT code here to cleanup the scene

    – e.g. remove display objects, remove touch listeners, save state, etc

end


– Listener setup

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene