Skip to content

Commit

Permalink
Recursive select options bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudwijma committed May 9, 2024
1 parent 34514cd commit 2722912
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Sys/SysModUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonArray>()) { //array of options
for (JsonVariant option : options.as<JsonArray>()) {
Expand Down

0 comments on commit 2722912

Please sign in to comment.