From 9ce4376d0d5d00058af5fd9803afe0823e006a8e Mon Sep 17 00:00:00 2001 From: TD-er Date: Thu, 25 Jun 2026 17:09:49 +0200 Subject: [PATCH] [Forms] Add optional changed bool to simplify checking for changes As suggested here: https://github.com/letscontrolit/ESPEasy/pull/5390#discussion_r3474622331 --- src/src/WebServer/Markup_Forms.cpp | 40 +++++++++++++++++++++--------- src/src/WebServer/Markup_Forms.h | 24 ++++++++++++------ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/src/WebServer/Markup_Forms.cpp b/src/src/WebServer/Markup_Forms.cpp index 690d16cdf..1cbb01bb5 100644 --- a/src/src/WebServer/Markup_Forms.cpp +++ b/src/src/WebServer/Markup_Forms.cpp @@ -703,15 +703,19 @@ bool getCheckWebserverArg_int(const String& 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; if (getCheckWebserverArg_int(key, tmpVal)) { + if (changed != nullptr && value != tmpVal) + *changed = true; value = tmpVal; return true; } @@ -719,17 +723,21 @@ bool update_whenset_FormItemInt(const String& key, int& value) { } 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, - uint32_t & value) + uint32_t & value, + bool* changed) { uint32_t tmpVal; if (getCheckWebserverArg_int(key, tmpVal)) { + if (changed != nullptr && value != tmpVal) + *changed = true; value = tmpVal; return true; } @@ -738,16 +746,20 @@ bool update_whenset_FormItemInt(const String& 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; if (getCheckWebserverArg_int(key, tmpVal)) { + if (changed != nullptr && value != tmpVal) + *changed = true; value = tmpVal; return true; } @@ -755,16 +767,20 @@ bool update_whenset_FormItemInt(const String& key, int8_t& value) { } 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; if (getCheckWebserverArg_int(key, tmpVal)) { + if (changed != nullptr && value != tmpVal) + *changed = true; value = tmpVal; return true; } diff --git a/src/src/WebServer/Markup_Forms.h b/src/src/WebServer/Markup_Forms.h index 85d5a2e0c..f771f8da9 100644 --- a/src/src/WebServer/Markup_Forms.h +++ b/src/src/WebServer/Markup_Forms.h @@ -330,28 +330,36 @@ bool getCheckWebserverArg_int(const String& key, uint32_t & value); bool update_whenset_FormItemInt(const __FlashStringHelper * key, - int & value); + int & value, + bool* changed = nullptr); bool update_whenset_FormItemInt(const String& key, - int & value); + int & value, + bool* changed = nullptr); bool update_whenset_FormItemInt(const __FlashStringHelper * key, - uint32_t & value); + uint32_t & value, + bool* changed = nullptr); bool update_whenset_FormItemInt(const String& key, - uint32_t & value); + uint32_t & value, + bool* changed = nullptr); bool update_whenset_FormItemInt(const __FlashStringHelper * key, - int8_t & value); + int8_t & value, + bool* changed = nullptr); bool update_whenset_FormItemInt(const String& key, - int8_t & value); + int8_t & value, + bool* changed = nullptr); bool update_whenset_FormItemInt(const __FlashStringHelper * key, - uint8_t & value); + uint8_t & value, + bool* changed = nullptr); 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. // So if webserver does not have an argument for a checkbox form, it means it should be considered unchecked.