Skip to content

Commit

Permalink
Introduce printSetInputMaxlength to properly set an inputs maxlength …
Browse files Browse the repository at this point in the history
…variable
  • Loading branch information
WouterGritter committed Nov 21, 2024
1 parent 4cd4c13 commit 49fb16e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ size_t printSetFormValue(Print& settingsScript, const char* key, int val);
size_t printSetFormValue(Print& settingsScript, const char* key, const char* val);
size_t printSetFormIndex(Print& settingsScript, const char* key, int index);
size_t printSetClassElementHTML(Print& settingsScript, const char* key, const int index, const char* val);
size_t printSetInputMaxLength(Print& settingsScript, const char* key, int val);
void prepareHostname(char* hostname);
bool isAsterisksOnly(const char* str, byte maxLen);
bool requestJSONBufferLock(uint8_t module=255);
Expand Down
4 changes: 4 additions & 0 deletions wled00/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ size_t printSetClassElementHTML(Print& settingsScript, const char* key, const in
return settingsScript.printf_P(PSTR("d.getElementsByClassName(\"%s\")[%d].innerHTML=\"%s\";"), key, index, val);
}

size_t printSetInputMaxLength(Print& settingsScript, const char* key, int val) {
return settingsScript.printf_P(PSTR("d.Sf.%s.setAttribute(\"maxlength\", %d);"),key,val);
}



void prepareHostname(char* hostname)
Expand Down
5 changes: 3 additions & 2 deletions wled00/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,9 @@ void getSettingsJS(byte subPage, Print& settingsScript)
printSetFormValue(settingsScript,PSTR("MG"),mqttGroupTopic);
printSetFormCheckbox(settingsScript,PSTR("BM"),buttonPublishMqtt);
printSetFormCheckbox(settingsScript,PSTR("RT"),retainMqttMsg);
settingsScript.printf_P(PSTR("d.Sf.MD.maxlength=%d;d.Sf.MG.maxlength=%d;d.Sf.MS.maxlength=%d;"),
MQTT_MAX_TOPIC_LEN, MQTT_MAX_TOPIC_LEN, MQTT_MAX_SERVER_LEN);
printSetInputMaxLength(settingsScript, PSTR("MD"), MQTT_MAX_TOPIC_LEN);
printSetInputMaxLength(settingsScript, PSTR("MG"), MQTT_MAX_TOPIC_LEN);
printSetInputMaxLength(settingsScript, PSTR("MS"), MQTT_MAX_SERVER_LEN);
#else
settingsScript.print(F("toggle('MQTT');")); // hide MQTT settings
#endif
Expand Down

0 comments on commit 49fb16e

Please sign in to comment.