@Jim another bug and this one’s a regression it was fixed in the last version and it back again but with a little twist.
When using dynamic pages and HREF to pass parameters to a page, it doesn’t pass the parameter for the link clicked. Here is the sample app to replicate it:
definition(
name: "Test HREF App",
namespace: "rboy",
author: "rboy",
description: "Test HREF Pages",
category: "SmartThings Labs",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/App-LightUpMyWorld.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/App-LightUpMyWorld@2x.png"
)
preferences {
page(name: "main")
page(name: "testPage")
}
def main() {
dynamicPage(name: "main", title: "HREF Test", uninstall: true, install: true) {
for (int i = 1; i <= 5; i++) {
def priorName = settings."userNames${i}"
section("User #${i}") {
if (priorName) {
input name: "userNames${i}", description: "${priorName}", title: "Name", defaultValue: priorName, type: "text", multiple: false, required: false, submitOnChange: true
} else {
input name: "userNames${i}", description: "Tap to set", title: "Name", type: "text", multiple: false, required: false, submitOnChange: true
}
def hrefParams = [
user: i as String,
passed: true
]
log.trace "$i Params: $hrefParams"
href(name: "testPage", params: hrefParams, title: "Click here to define actions for ${settings."userNames${i}"}", page: "testPage", description: "", required: false)
}
}
section("Mode Change Open Door/Window/Switch Notification") {
def modes = location.modes
for (mode in modes) {
// Unlock actions for each mode
def hrefParams1 = [
user: mode as String,
passed: true
]
href(name: "modeDoorMonitor", params: hrefParams1, title: "When switching to mode ${mode}", page: "testPage", description: "", required: false)
}
}
}
}
def testPage(params) {
// params is broken, after doing a submitOnChange on this page, params is lost. So as a work around when this page is called with params save it to state and if the page is called with no params we know it's the bug and use the last state instead
if (params.passed) {
atomicState.params = params // We got something, so save it otherwise it's a page refresh for submitOnChange
}
def user = atomicState.params?.user ?: ""
def name = user ? settings."userNames${user}" : ""
log.trace "Actions Page, user:$user, name:$name, passed params: $params, saved params:$atomicState.params"
dynamicPage(name:"testPage", title: "Setup actions for each door" + (user ? " for user $name." : ""), uninstall: false, install: false) {
section {
input "userOverrideUnlockActions${user}", "bool", title: "Define specific actions for $name", required: true, submitOnChange: true
}
}
}
def initialize() {
}
def updated() {
}
This works fine on iOS and the previous version of the Android but with 2.1.6 try this simple test. Install the SmartApp.
Now enter 4 user names. Then click on the “Click here to define actions” for each user starting from 1 to 4. All good. Now do it random order, e.g 4 then 1 then 3 then 2 etc. You’ll find that it’s passing the wrong HREF data to the pages.
Thanks to @gjanes for bring this to our attention. This is impact all of the apps which use HREF and dynamic pages.
There is another issue as reported by @gjanes, in Android when entering data into a field, unless you click Done on the keypad it doesn’t register the data. So if you have a required input field and you type in the data and click on install/done on the SmartApp before clicking done on the keypad or changing fields it will throw an error that a field is missing (i.e. it hasn’t registered the entered data).