From 272291285d9f71a4395ccd96c3cf448328ed3cf4 Mon Sep 17 00:00:00 2001 From: Ewoud Date: Thu, 9 May 2024 11:12:33 +0200 Subject: [PATCH] Recursive select options bugfix --- src/Sys/SysModUI.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Sys/SysModUI.h b/src/Sys/SysModUI.h index 04da3853..d499786d 100644 --- a/src/Sys/SysModUI.h +++ b/src/Sys/SysModUI.h @@ -274,17 +274,22 @@ class SysModUI: public SysModule { web->getResponseObject()[mdl->varID(var)].remove("options"); } - //find options text in a hierarchy of options (groupName and optionName as pointers? String is already a pointer?) - void findOptionsText(JsonObject var, uint8_t value, JsonString *groupName, JsonString *optionName) { + //find options text in a hierarchy of options + void findOptionsText(JsonObject var, uint8_t value, char * groupName, char * optionName) { uint8_t startValue = 0; bool optionsExisted = !web->getResponseObject()[mdl->varID(var)]["options"].isNull(); + JsonString groupNameJS; + JsonString optionNameJS; JsonArray options = getOptions(var); - if (!findOptionsTextRec(options, &startValue, value, groupName, optionName)) - ppf("findOptions select option not found %d %s %s\n", value, (*groupName).isNull()?"X":(*groupName).c_str(), (*optionName).isNull()?"X":(*optionName).c_str()); + if (!findOptionsTextRec(options, &startValue, value, &groupNameJS, &optionNameJS)) + ppf("findOptions select option not found %d %s %s\n", value, groupNameJS.isNull()?"X":groupNameJS.c_str(), optionNameJS.isNull()?"X":optionNameJS.c_str()); + strcpy(groupName, groupNameJS.c_str()); + strcpy(optionName, optionNameJS.c_str()); if (!optionsExisted) - clearOptions(var); + clearOptions(var); //if created here then also remove } + // (groupName and optionName as pointers? String is already a pointer?) bool findOptionsTextRec(JsonVariant options, uint8_t * startValue, uint8_t value, JsonString *groupName, JsonString *optionName, JsonString parentGroup = JsonString()) { if (options.is()) { //array of options for (JsonVariant option : options.as()) {