Question regarding buttons in an app

In an app, my goal is to have a button run a method in the same app.

Below is some code I found on this forum. And I think it tells the answer but I also think I'm missing something.

Question:
In the line:

input(name: "pauseButton", type: "button", title: "Pause",

The type being "button" results in the execution of the below method:

def appButtonHandler(btn) {

This suggests the type: "button" kind of relates to "btn" as the parameter passed to "def appButtonHandler(btn)"

Do I have this correct? I was not able to find anything in the documentation.
Thanks
John

section(){
			if (!state.isPaused) {
				input(name: "pauseButton", type: "button", title: "Pause", backgroundColor: "Green", textColor: "white", submitOnChange: true)
			} else {
				input(name: "resumeButton", type: "button", title: "Resume", backgroundColor: "Crimson", textColor: "white", submitOnChange: true)
			}
		}
.
.
.
.
def appButtonHandler(btn) {
    switch(btn) {
        case "pauseButton":
			state.isPaused = true
            break
		case "resumeButton":
			state.isPaused = false
			break
    }
    updated()
}

That's pretty close. I'm not sure why there is the call to updated() in appButtonHandler; that would make the app re-initialize on every button push of the ui.

1 Like

Thank you.

The code I posted was not from a completed App so I'll guess the updated didn't make it into the final code.

It could be something that someone wanted to do, it's just not the way you'd normally go about that. An Update button could be added, just like the other two, and that one could call updated. It all depends on what you want the UI to look like. Most apps don't need or use and Updated button.

2 Likes