[Forms] Add optional changed bool to simplify checking for changes

As suggested here: https://github.com/letscontrolit/ESPEasy/pull/5390#discussion_r3474622331
This commit is contained in:
TD-er
2026-06-25 17:09:49 +02:00
parent d61d4ecdc6
commit 9ce4376d0d
2 changed files with 44 additions and 20 deletions
+28 -12
View File
@@ -703,15 +703,19 @@ bool getCheckWebserverArg_int(const String& key,
} }
bool update_whenset_FormItemInt(const __FlashStringHelper * key, bool update_whenset_FormItemInt(const __FlashStringHelper * key,
int & value) int & value,
bool* changed)
{ {
return update_whenset_FormItemInt(String(key), value); return update_whenset_FormItemInt(String(key), value, changed);
} }
bool update_whenset_FormItemInt(const String& key, int& value) { bool update_whenset_FormItemInt(const String& key, int& value,
bool* changed) {
int tmpVal; int tmpVal;
if (getCheckWebserverArg_int(key, tmpVal)) { if (getCheckWebserverArg_int(key, tmpVal)) {
if (changed != nullptr && value != tmpVal)
*changed = true;
value = tmpVal; value = tmpVal;
return true; return true;
} }
@@ -719,17 +723,21 @@ bool update_whenset_FormItemInt(const String& key, int& value) {
} }
bool update_whenset_FormItemInt(const __FlashStringHelper * key, bool update_whenset_FormItemInt(const __FlashStringHelper * key,
uint32_t & value) uint32_t & value,
bool* changed)
{ {
return update_whenset_FormItemInt(String(key), value); return update_whenset_FormItemInt(String(key), value, changed);
} }
bool update_whenset_FormItemInt(const String& key, bool update_whenset_FormItemInt(const String& key,
uint32_t & value) uint32_t & value,
bool* changed)
{ {
uint32_t tmpVal; uint32_t tmpVal;
if (getCheckWebserverArg_int(key, tmpVal)) { if (getCheckWebserverArg_int(key, tmpVal)) {
if (changed != nullptr && value != tmpVal)
*changed = true;
value = tmpVal; value = tmpVal;
return true; return true;
} }
@@ -738,16 +746,20 @@ bool update_whenset_FormItemInt(const String& key,
bool update_whenset_FormItemInt(const __FlashStringHelper * key, bool update_whenset_FormItemInt(const __FlashStringHelper * key,
int8_t& value) int8_t& value,
bool* changed)
{ {
return update_whenset_FormItemInt(String(key), value); return update_whenset_FormItemInt(String(key), value, changed);
} }
bool update_whenset_FormItemInt(const String& key, int8_t& value) { bool update_whenset_FormItemInt(const String& key, int8_t& value,
bool* changed) {
int tmpVal; int tmpVal;
if (getCheckWebserverArg_int(key, tmpVal)) { if (getCheckWebserverArg_int(key, tmpVal)) {
if (changed != nullptr && value != tmpVal)
*changed = true;
value = tmpVal; value = tmpVal;
return true; return true;
} }
@@ -755,16 +767,20 @@ bool update_whenset_FormItemInt(const String& key, int8_t& value) {
} }
bool update_whenset_FormItemInt(const __FlashStringHelper * key, bool update_whenset_FormItemInt(const __FlashStringHelper * key,
uint8_t& value) uint8_t& value,
bool* changed)
{ {
return update_whenset_FormItemInt(String(key), value); return update_whenset_FormItemInt(String(key), value, changed);
} }
bool update_whenset_FormItemInt(const String& key, uint8_t& value) { bool update_whenset_FormItemInt(const String& key, uint8_t& value,
bool* changed) {
int tmpVal; int tmpVal;
if (getCheckWebserverArg_int(key, tmpVal)) { if (getCheckWebserverArg_int(key, tmpVal)) {
if (changed != nullptr && value != tmpVal)
*changed = true;
value = tmpVal; value = tmpVal;
return true; return true;
} }
+16 -8
View File
@@ -330,28 +330,36 @@ bool getCheckWebserverArg_int(const String& key,
uint32_t & value); uint32_t & value);
bool update_whenset_FormItemInt(const __FlashStringHelper * key, bool update_whenset_FormItemInt(const __FlashStringHelper * key,
int & value); int & value,
bool* changed = nullptr);
bool update_whenset_FormItemInt(const String& key, bool update_whenset_FormItemInt(const String& key,
int & value); int & value,
bool* changed = nullptr);
bool update_whenset_FormItemInt(const __FlashStringHelper * key, bool update_whenset_FormItemInt(const __FlashStringHelper * key,
uint32_t & value); uint32_t & value,
bool* changed = nullptr);
bool update_whenset_FormItemInt(const String& key, bool update_whenset_FormItemInt(const String& key,
uint32_t & value); uint32_t & value,
bool* changed = nullptr);
bool update_whenset_FormItemInt(const __FlashStringHelper * key, bool update_whenset_FormItemInt(const __FlashStringHelper * key,
int8_t & value); int8_t & value,
bool* changed = nullptr);
bool update_whenset_FormItemInt(const String& key, bool update_whenset_FormItemInt(const String& key,
int8_t & value); int8_t & value,
bool* changed = nullptr);
bool update_whenset_FormItemInt(const __FlashStringHelper * key, bool update_whenset_FormItemInt(const __FlashStringHelper * key,
uint8_t & value); uint8_t & value,
bool* changed = nullptr);
bool update_whenset_FormItemInt(const String& key, bool update_whenset_FormItemInt(const String& key,
uint8_t & value); uint8_t & value,
bool* changed = nullptr);
// Note: Checkbox values will not appear in POST Form data if unchecked. // Note: Checkbox values will not appear in POST Form data if unchecked.
// So if webserver does not have an argument for a checkbox form, it means it should be considered unchecked. // So if webserver does not have an argument for a checkbox form, it means it should be considered unchecked.