diff --git a/mkdocs/apielements.md b/mkdocs/apielements.md index 235ec67..c80abcd 100644 --- a/mkdocs/apielements.md +++ b/mkdocs/apielements.md @@ -441,7 +441,9 @@ Indicates the check of the specified option for the radio buttons. You can use t ```cpp void empty(const size_t reserve = 0) ``` -Clear the array of option strings that AutoConnectRadio has in the values. When a **_reserve_** parameter is specified, a vector container of that size is reserved. +Clear the array of option strings that AutoConnectRadio has in the values. When the **_reserve_** parameter is specified, a vector container of that size is reserved. + +The empty function resets the checked value to zero. When the empty function is executed, any button will be turned off.
**Parameter**
reserveReserved size of a container for the radio button option strings.
@@ -560,7 +562,9 @@ Adds a selectable option string for the selection list. ```cpp void empty(const size_t reserve = 0) ``` -Clear the array of options list that AutoConnectSelect has in the options. When a **_reserve_** parameter is specified, a vector container of that size is reserved. +Clear the array of options list that AutoConnectSelect has in the options. When the **_reserve_** parameter is specified, a vector container of that size is reserved. + +The empty function resets the selected value to zero. When the empty function is executed, there are no selected options and the first item is placed at the beginning.
**Parameter**
reserveReserved size of a container for the options.
diff --git a/src/AutoConnectElementJsonImpl.h b/src/AutoConnectElementJsonImpl.h index dca6f6b..766a9bf 100644 --- a/src/AutoConnectElementJsonImpl.h +++ b/src/AutoConnectElementJsonImpl.h @@ -277,6 +277,12 @@ bool AutoConnectRadioJson::loadMember(const JsonObject& json) { _setMember(json); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_LABEL))) label = json[F(AUTOCONNECT_JSON_KEY_LABEL)].as(); + if (json.containsKey(F(AUTOCONNECT_JSON_KEY_VALUE))) { + ArduinoJsonArray optionArray = json[AUTOCONNECT_JSON_KEY_VALUE]; + empty(optionArray.size()); + for (auto value : optionArray) + add(value.as()); + } if (json.containsKey(F(AUTOCONNECT_JSON_KEY_CHECKED))) checked = static_cast(json[F(AUTOCONNECT_JSON_KEY_CHECKED)].as()); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_ARRANGE))) { @@ -290,13 +296,6 @@ bool AutoConnectRadioJson::loadMember(const JsonObject& json) { return false; } } - if (json.containsKey(F(AUTOCONNECT_JSON_KEY_VALUE))) { - empty(); - // JsonArray& optionArray = json[AUTOCONNECT_JSON_KEY_VALUE]; - ArduinoJsonArray optionArray = json[AUTOCONNECT_JSON_KEY_VALUE]; - for (auto value : optionArray) - add(value.as()); - } return true; } return false; @@ -350,14 +349,14 @@ bool AutoConnectSelectJson::loadMember(const JsonObject& json) { if (json.containsKey(F(AUTOCONNECT_JSON_KEY_LABEL))) label = json[F(AUTOCONNECT_JSON_KEY_LABEL)].as(); if (json.containsKey(F(AUTOCONNECT_JSON_KEY_OPTION))) { - empty(); ArduinoJsonArray optionArray = json[AUTOCONNECT_JSON_KEY_OPTION]; + empty(optionArray.size()); for (auto value : optionArray) add(value.as()); - if (json.containsKey(F(AUTOCONNECT_JSON_KEY_SELECTED))) - selected = static_cast(json[F(AUTOCONNECT_JSON_KEY_SELECTED)].as()); - return true; } + if (json.containsKey(F(AUTOCONNECT_JSON_KEY_SELECTED))) + selected = static_cast(json[F(AUTOCONNECT_JSON_KEY_SELECTED)].as()); + return true; } return false; }