From 23c5e21df82b4484de1000d48ac4ad397f8f2420 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Mon, 24 Dec 2018 17:02:45 +0900 Subject: [PATCH] Fix AutoConnectCheckbox value missing. --- src/AutoConnectAux.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/AutoConnectAux.cpp b/src/AutoConnectAux.cpp index aff1889..f5a2116 100644 --- a/src/AutoConnectAux.cpp +++ b/src/AutoConnectAux.cpp @@ -349,13 +349,22 @@ PageElement* AutoConnectAux::_setupPage(String uri) { * @param webServer A pointer to the class object of WebServerClass */ void AutoConnectAux::_storeElements(WebServerClass* webServer) { - for (uint8_t n = 0; n < webServer->args(); n++) { - String elmValue = webServer->arg(n); - AutoConnectElement* elm = getElement(webServer->argName(n)); - if (elm) { - if (elm->typeOf() == AC_Checkbox) - elmValue = "checked"; - setElementValue(webServer->argName(n), elmValue); + for (AutoConnectElement& elm : _addonElm) { + // Overwrite the value of all cataloged AutoConnectElements with + // arguments inherited from the last http request. + // Relies on AutoConnectRadio, it restores to false at the being + // because the checkbox argument will not pass if it is not checked. + if (elm.typeOf() == AC_Checkbox) + reinterpret_cast(elm).checked = false; + + // Seek by argument, store the value to its element. + for (int8_t n = 0; n < static_cast(webServer->args()); n++) { + if (webServer->argName(n).equalsIgnoreCase(elm.name)) { + String elmValue = webServer->arg(n); + if (elm.typeOf() == AC_Checkbox) + elmValue = "checked"; + setElementValue(elm.name, elmValue); + } } } }