Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textarea fields in usermods #4217

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions usermods/EXAMPLE_v2/usermod_v2_example.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MyExampleUsermod : public Usermod {
unsigned long testULong = 42424242;
float testFloat = 42.42;
String testString = "Forty-Two";
String testMultilineString = "Forty...\nTwo"; // Key has > as final character, makes it multiline

// These config variables have defaults set inside readFromConfig()
int testInt;
Expand Down Expand Up @@ -232,6 +233,7 @@ class MyExampleUsermod : public Usermod {
top["testULong"] = testULong;
top["testFloat"] = testFloat;
top["testString"] = testString;
top["testMultilineString>"] = testMultilineString; // Key has > as final character, makes it multiline
JsonArray pinArray = top.createNestedArray("pin");
pinArray.add(testPins[0]);
pinArray.add(testPins[1]);
Expand Down Expand Up @@ -267,6 +269,17 @@ class MyExampleUsermod : public Usermod {
configComplete &= getJsonValue(top["testULong"], testULong);
configComplete &= getJsonValue(top["testFloat"], testFloat);
configComplete &= getJsonValue(top["testString"], testString);
configComplete &= getJsonValue(top["testMultilineString>"], testMultilineString);

// Remove any carriage returns (\r) from testMultilineString, leave only newlines (\n)
int i=0;
int lastI;
while(true) {
lastI = i;
i = testMultilineString.indexOf('\r',lastI);
if (i < 0) break;
testMultilineString.remove(i,1);
}

// A 3-argument getJsonValue() assigns the 3rd argument as a default value if the Json value is missing
configComplete &= getJsonValue(top["testInt"], testInt, 42);
Expand Down
9 changes: 7 additions & 2 deletions wled00/data/settings_um.htm
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,19 @@
}
break;
default:
t = "text"; c = `value="${o}" style="width:250px;"`;
if (f.substr(-1)===">") {
t = "textarea"; c = `style="width:300px;height:150px;"`;
} else {
t = "text"; c = `value="${o}" style="width:250px;"`;
}
break;
}
urows += ` ${initCap(f)} `; //only show field (key is shown in grouping)
// https://stackoverflow.com/questions/11657123/posting-both-checked-and-unchecked-checkboxes
if (t=="checkbox") urows += `<input type="hidden" name="${k}:${f}${a?"[]":""}" value="false">`;
else if (!a) urows += `<input type="hidden" name="${k}:${f}${a?"[]":""}" value="${t}">`;
urows += `<input type="${t==="int"?"number":t}" name="${k}:${f}${a?"[]":""}" ${c} oninput="check(this,'${k.substr(k.indexOf(":")+1)}')"><br>`;
if (t=="textarea") urows += `<br><textarea name="${k}:${f}${a?"[]":""}" ${c}>${o}</textarea><br>`;
else urows += `<input type="${t==="int"?"number":t}" name="${k}:${f}${a?"[]":""}" ${c} oninput="check(this,'${k.substr(k.indexOf(":")+1)}')"><br>`;
}
}
function pinDropdowns() {
Expand Down
2 changes: 1 addition & 1 deletion wled00/data/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ button.sml {
.warn {
color: #fa0;
}
input {
input, textarea {
background: #333;
color: #fff;
font-family: Verdana, sans-serif;
Expand Down