My Button Function Isn't Working

Hi guys,

I’m trying to make my scene go to the next using the composer providing all my textboxes have input inside and one of my two switches is on. If not I wanted it to show an alert to saying which one needs input. But its not working the way I wanted and I can’t work out how it should look. Could someone please help me out here?

[lua]

local function OnbtnNext( event )

    if event.phase == “ended” then

myData.dateDay = textBoxDay.text

myData.dateMonth = textBoxMonth.text

myData.dateYear = textBoxYear.text

myData.timeHour = textBoxHour.text

myData.timeMinute = textBoxMinute.text

end

if  radioButton1.isOn == true then

    myData.IRb1 = textWasThisA.text

    end

    if radioButton2.isOn == true then

    myData.IRb1 = textWasThis.text

    end

    if textBoxDay.text == “” or textBoxDay.text == nil or 

    textBoxMonth.text == “” or textBoxMonth.text == nil or

    textBoxYear.text == “” or textBoxYear.text == nil or

    textBoxHour.text == “” or textBoxHour.text == nil or

    textBoxMinute.text == “” or textBoxMinute.text == nil then

        local alert = native.showAlert( “Warning”, “ERROR: No input in textbox(s)”, { “OK” }, onComplete)

end

    if radioButton1.isOn == true or radioButton2.isOn == true and textBoxDay.text ~= “” or textBoxMonth.text ~= “” or textBoxYear.text ~= “” or textBoxHour.text ~= “” or textBoxMinute.text ~= “”  then

        composer.gotoScene( “incidentReportingPg3”, { effect=“slideLeft”, time=800,} )

    

    elseif radioButton1.isOn == false and radioButton2.isOn == false then

        local alert = native.showAlert( “Warning”, “ERROR: No input in checkbox(s)”, { “OK” }, onComplete)

    end

return true

end

[/lua]

Thanks again,

Matt.

[lua]

local function OnbtnNext( event )

      if event.phase == “ended” then

            local radioOn = false

            local textFilled = true

            myData.dateDay = textBoxDay.text

            myData.dateMonth = textBoxMonth.text

            myData.dateYear = textBoxYear.text

            myData.timeHour = textBoxHour.text

            myData.timeMinute = textBoxMinute.text

            if radioButton1.isOn == true then

            myData.IRb1 = textWasThisA.text

                  radioOn = true

          end

            if radioButton2.isOn == true then

           myData.IRb1 = textWasThis.text

                  radioOn = true

            end

      if textBoxDay.text == “” or textBoxDay.text == nil or

          textBoxMonth.text == “” or textBoxMonth.text == nil or

      textBoxYear.text == “” or textBoxYear.text == nil or

            textBoxHour.text == “” or textBoxHour.text == nil or

          textBoxMinute.text == “” or textBoxMinute.text == nil then

                  textFilled = false

           end

            if radioOn and textFilled then

                   composer.gotoScene( “incidentReportingPg3”, { effect=“slideLeft”, time= 800 ,} )

            else

                  local msg

                  if radioOn == false and textFilled == false then

                        msg = “No input in checkbox(s) and textbox(s)”

                  else

                        if radioOn then

                              msg = “No input in checkbox(s)”

                        else

                              msg = “No input in textbox(s)”

                        end

                  end

                  local alert = native.showAlert( “Warning”, "ERROR: " …m sg, { “OK” }, onComplete)

            end

       

      end

      return true

end

[/lua]

Hi Nick,

I tried your code and it works perfectly, the only issue was that it was displaying the alert the wrong way round. Say there was no data in the text fields but data in the checkboxes an alert would pop up saying there was no input in the checkboxes so I simply swapped the around an it seems to have done the trick now.

Thanks for your help.

Matt.

[lua]

local function OnbtnNext( event )

      if event.phase == “ended” then

            local radioOn = false

            local textFilled = true

            myData.dateDay = textBoxDay.text

            myData.dateMonth = textBoxMonth.text

            myData.dateYear = textBoxYear.text

            myData.timeHour = textBoxHour.text

            myData.timeMinute = textBoxMinute.text

            if radioButton1.isOn == true then

            myData.IRb1 = textWasThisA.text

                  radioOn = true

          end

            if radioButton2.isOn == true then

           myData.IRb1 = textWasThis.text

                  radioOn = true

            end

      if textBoxDay.text == “” or textBoxDay.text == nil or

          textBoxMonth.text == “” or textBoxMonth.text == nil or

      textBoxYear.text == “” or textBoxYear.text == nil or

            textBoxHour.text == “” or textBoxHour.text == nil or

          textBoxMinute.text == “” or textBoxMinute.text == nil then

                  textFilled = false

           end

            if radioOn and textFilled then

                   composer.gotoScene( “incidentReportingPg3”, { effect=“slideLeft”, time= 800 ,} )

            else

                  local msg

                  if radioOn == false and textFilled == false then

                        msg = “No input in checkbox(s) and textbox(s)”

                  else

                        if radioOn then

                              msg = “No input in checkbox(s)”

                        else

                              msg = “No input in textbox(s)”

                        end

                  end

                  local alert = native.showAlert( “Warning”, "ERROR: " …m sg, { “OK” }, onComplete)

            end

       

      end

      return true

end

[/lua]

Hi Nick,

I tried your code and it works perfectly, the only issue was that it was displaying the alert the wrong way round. Say there was no data in the text fields but data in the checkboxes an alert would pop up saying there was no input in the checkboxes so I simply swapped the around an it seems to have done the trick now.

Thanks for your help.

Matt.