Hi Rob,
That was in fact the issue I believe however, my print( myData.IRb1 ) function is no longer working.Any ideas on why this is?
Thanks again,
Matt.
Hi Rob,
That was in fact the issue I believe however, my print( myData.IRb1 ) function is no longer working.Any ideas on why this is?
Thanks again,
Matt.
Well that print is in the else clause of a fairly complex if-then-elseif-elseif statement. Without tracing the values I can’t guess what values are controlling your logic. You just have to test it and it’s possible that your app simply cannot get to that else.
Rob
Hi Rob,
I have removed the else print( myData.IRb1 ) and simple put it on the scene which my composer is changing to providing one of the checkboxes is checked, and sure enough it is printing. However, it seams as if my checkbox still isn’t sending the data across to myData.lua as I have set the default value in myData.lua to [lua]myData.IRb1 = “empty”[/lua] and this is what is getting printed. Any ideas here?
Thanks,
Matt.
Can you repost your latest code?
Hi Rob,
Yes no problem this is my latest code.
[lua]
–
– incidentReportingPg1.lua
–
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require( “widget” )
local myData = require( “myData” )
function onComplete( event )
if event.action == “clicked” then
local i = event.index
if i == 1 then
end
end
end
function scene:create( event )
local sceneGroup = self.view
–bg
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX = 0
bg.anchorY = 0
bg:setFillColor( 0.9, 0.9, 0.9 ) – white
sceneGroup:insert ( bg )
–titleHeader
local titleHeader = display.newImage( “titleHeader.png” )
titleHeader:translate( 160, -22 )
–title
local title = display.newText( “Incident Reporting”, 0, 0, native.systemFont, 32 )
title:setFillColor( 0 ) – black
title.x = display.contentWidth * 0.5
title.y = -25
–textPage
local textPage = display.newText(“Page 22”,
280,130, display.contentWidth -25 , display.contentHeight * 0.5, native.systemFont, 15 )
textPage:setFillColor( 0, 0, 0 )
– Handle press events for the buttons
local function onSwitchPress( event )
local switch = event.target
print( “Switch with ID '”…switch.id…"’ is on: "…tostring(switch.isOn) )
end
– Image sheet options and declaration
local options = {
width = 26,
height = 26,
numFrames = 2,
sheetContentWidth = 26,
sheetContentHeight = 52
}
local checkboxSheet = graphics.newImageSheet( “checkboxSheet.png”, options )
– Create a group for the radio button set
local radioGroup = display.newGroup()
– Create two associated radio buttons (inserted into the same display group)
local radioButton1 = widget.newSwitch
{
left = 20,
top = 100,
style = “radio”,
id = “RadioButton1”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton1 )
sceneGroup:insert( radioButton1 )
local radioButton2 = widget.newSwitch
{
left = 20,
top = 140,
style = “radio”,
id = “RadioButton2”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton2 )
sceneGroup:insert( radioButton2 )
local radioButton3 = widget.newSwitch
{
left = 20,
top = 180,
style = “radio”,
id = “RadioButton3”,
width = 26,
height = 26,
onPress = onSwitchPress,
sheet = checkboxSheet,
frameOff = 1,
frameOn = 2
}
radioGroup:insert( radioButton3 )
sceneGroup:insert( radioButton3 )
–textCheck1
local textCheck1 = display.newText(“textCheck1”,
210, 225, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textCheck1:setFillColor( 0, 0, 0 )
sceneGroup:insert( textCheck1 )
–textCheck2
local textCheck2 = display.newText(“textCheck2”,
210, 265, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textCheck2:setFillColor( 0, 0, 0 )
sceneGroup:insert( textCheck2 )
–textCheck3
local textCheck3 = display.newText(“textCheck3”,
210, 305, display.contentWidth, display.contentHeight * 0.5, native.systemFont, 13 )
textCheck3:setFillColor( 0, 0, 0 )
sceneGroup:insert( textCheck3 )
function OnBtnNext( event )
if radioButton1.isOn == true or radioButton2.isOn == true or radioButton3.isOn == true then
composer.gotoScene( “riskAssessmentPg1”, { effect=“slideLeft”, time=800,} )
elseif radioButton1.isOn == false and radioButton2.isOn == false and radioButton3.isOn == false then
local alert = native.showAlert( “Warning”, “ERROR: No input in checkbox(s)”, { “OK” }, onComplete)
elseif radioButton1.isOn == true then
myData.IRb1 = textCheck1
end
end
–btnNext
local btnNext = widget.newButton
{
width = 150,
height = 40,
defaultFile = “btnNext.png”,
onEvent = OnBtnNext
}
btnNext.x = 235
btnNext.y = 445
local function home( event )
composer.gotoScene( “forms”, { effect=“slideRight”, time=800} )
end
local btnHome = widget.newButton
{
width = 320,
height = 50,
defaultFile = “home.png”,
onEvent = home,
}
btnHome.x = 160
btnHome.y = 499
–sceneGroup
sceneGroup:insert( titleHeader )
sceneGroup:insert( title )
sceneGroup:insert( textPage )
sceneGroup:insert( btnNext )
end
function scene:show( event )
local sceneGroup = self.view
end
function scene:hide( event )
local sceneGroup = self.view
end
function scene:destroy( event )
local sceneGroup = self.view
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
Thanks again,
Matt.
function OnBtnNext( event ) if radioButton1.isOn == true or radioButton2.isOn == true or radioButton3.isOn == true then composer.gotoScene( "riskAssessmentPg1", { effect="slideLeft", time=800,} ) elseif radioButton1.isOn == false and radioButton2.isOn == false and radioButton3.isOn == false then local alert = native.showAlert( "Warning", "ERROR: No input in checkbox(s)", { "OK" }, onComplete) elseif radioButton1.isOn == true then myData.IRb1 = textCheck1 end end
Your last elseif will never, every be reached.
If radioButton1.isOn is true, the first “if” clause will be true and you will goto the scene and never make it here. If all three check boxes are off, your alert will fire and never make it to the third block. You probably want something like this:
function OnBtnNext( event ) if radioButton1.isOn == true then myData.IRb1 = textCheck1 end if radioButton1.isOn == true or radioButton2.isOn == true or radioButton3.isOn == true then composer.gotoScene( "riskAssessmentPg1", { effect="slideLeft", time=800,} ) elseif radioButton1.isOn == false and radioButton2.isOn == false and radioButton3.isOn == false then local alert = native.showAlert( "Warning", "ERROR: No input in checkbox(s)", { "OK" }, onComplete) end end
Rob
Hi Brent,
This has worked perfectly now thank you for your assistances here.
Matt.