Fixed to reset selected value after clearing option array

pull/83/head
Hieromon Ikasamo 6 years ago committed by Hieromon Ikasamo
parent 921c49e747
commit fb3de08f9e
  1. 8
      mkdocs/apielements.md
  2. 21
      src/AutoConnectElementJsonImpl.h

@ -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.
<dl class="apidl">
<dt>**Parameter**</dt>
<dd><span class="apidef">reserve</span><span class="apidesc">Reserved size of a container for the radio button option strings.</span></dd>
@ -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.
<dl class="apidl">
<dt>**Parameter**</dt>
<dd><span class="apidef">reserve</span><span class="apidesc">Reserved size of a container for the options.</span></dd>

@ -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<String>();
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<String>());
}
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_CHECKED)))
checked = static_cast<uint8_t>(json[F(AUTOCONNECT_JSON_KEY_CHECKED)].as<int>());
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<String>());
}
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<String>();
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<String>());
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_SELECTED)))
selected = static_cast<uint8_t>(json[F(AUTOCONNECT_JSON_KEY_SELECTED)].as<int>());
return true;
}
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_SELECTED)))
selected = static_cast<uint8_t>(json[F(AUTOCONNECT_JSON_KEY_SELECTED)].as<int>());
return true;
}
return false;
}

Loading…
Cancel
Save