From 4dd1a9e516afb4e68c0d3a2ce361d05de551d6e4 Mon Sep 17 00:00:00 2001 From: technyon Date: Sun, 5 Feb 2023 12:23:24 +0100 Subject: [PATCH] show length restrictions on some input fields --- WebCfgServer.cpp | 38 +++++++++++++++++++++++++++----------- WebCfgServer.h | 4 ++-- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/WebCfgServer.cpp b/WebCfgServer.cpp index 7b6ad63..9c3ebcb 100644 --- a/WebCfgServer.cpp +++ b/WebCfgServer.cpp @@ -519,8 +519,8 @@ void WebCfgServer::buildCredHtml(String &response) response.concat("
"); response.concat("

Credentials

"); response.concat(""); - printInputField(response, "CREDUSER", "User (# to clear)", _preferences->getString(preference_cred_user).c_str(), 30); - printInputField(response, "CREDPASS", "Password (max 30 characters)", "*", 30, true); + printInputField(response, "CREDUSER", "User (# to clear)", _preferences->getString(preference_cred_user).c_str(), 30, false, true); + printInputField(response, "CREDPASS", "Password", "*", 30, true, true); printInputField(response, "CREDPASSRE", "Retype password", "*", 30, true); response.concat("
"); response.concat("
"); @@ -610,16 +610,16 @@ void WebCfgServer::buildMqttConfigHtml(String &response) printInputField(response, "HOSTNAME", "Host name", _preferences->getString(preference_hostname).c_str(), 100); printInputField(response, "MQTTSERVER", "MQTT Broker", _preferences->getString(preference_mqtt_broker).c_str(), 100); printInputField(response, "MQTTPORT", "MQTT Broker port", _preferences->getInt(preference_mqtt_broker_port), 5); - printInputField(response, "MQTTUSER", "MQTT User (# to clear)", _preferences->getString(preference_mqtt_user).c_str(), 30); - printInputField(response, "MQTTPASS", "MQTT Password", "*", 30, true); + printInputField(response, "MQTTUSER", "MQTT User (# to clear)", _preferences->getString(preference_mqtt_user).c_str(), 30, false, true); + printInputField(response, "MQTTPASS", "MQTT Password", "*", 30, true, true); response.concat("
"); response.concat("

Advanced MQTT and Network Configuration

"); response.concat(""); printInputField(response, "HASSDISCOVERY", "Home Assistant discovery topic (empty to disable; usually homeassistant)", _preferences->getString(preference_mqtt_hass_discovery).c_str(), 30); - printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE, _network->encryptionSupported()); - printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE, _network->encryptionSupported()); - printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE, _network->encryptionSupported()); + printTextarea(response, "MQTTCA", "MQTT SSL CA Certificate (*, optional)", _preferences->getString(preference_mqtt_ca).c_str(), TLS_CA_MAX_SIZE, _network->encryptionSupported(), true); + printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE, _network->encryptionSupported(), true); + printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE, _network->encryptionSupported(), true); printDropDown(response, "NWHW", "Network hardware", String(_preferences->getInt(preference_network_hardware)), getNetworkDetectionOptions()); printDropDown(response, "NWHWDT", "Network hardware detection", String(_preferences->getInt(preference_network_hardware_gpio)), getNetworkGpioOptions()); printInputField(response, "RSSI", "RSSI Publish interval (seconds; -1 to disable)", _preferences->getInt(preference_rssi_publish_interval), 6); @@ -775,8 +775,9 @@ void WebCfgServer::printInputField(String& response, const char *token, const char *description, const char *value, - const size_t maxLength, - const bool isPassword) + const size_t& maxLength, + const bool& isPassword, + const bool& showLengthRestriction) { char maxLengthStr[20]; @@ -784,6 +785,14 @@ void WebCfgServer::printInputField(String& response, response.concat("
"); response.concat(description); + + if(showLengthRestriction) + { + response.concat(" (Max. "); + response.concat(maxLength); + response.concat(" characters)"); + } + response.concat(""); response.concat(""); response.concat(description); + if(showLengthRestriction) + { + response.concat(" (Max. "); + response.concat(maxLength); + response.concat(" characters)"); + } response.concat(""); response.concat("