Skip to content

Commit

Permalink
form fixes (#15)
Browse files Browse the repository at this point in the history
- fix id of html input for boolean variable
- html_table: switch forms to fieldset from a table
  • Loading branch information
chl33 authored Feb 25, 2024
1 parent 7a707c6 commit 195365e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
26 changes: 7 additions & 19 deletions src/html_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ void writeTableInto(String* out_str, const VariableGroup& vars, const char* titl
}

void writeFormRowInto(String* out_str, const VariableBase& var) {
*out_str += "<tr><td>";
*out_str += " <p><b>";
*out_str += var.human_str();
if (var.units() && var.units()[0]) {
*out_str += " (";
escape(out_str, var.units());
*out_str += ")";
}
*out_str += "</td><td>";
*out_str += "</b><br/>";
*out_str += var.formEntry();
*out_str += "</td></tr>\n";
*out_str += "</p>";
}

void writeFormRowsInto(String* out_str, const VariableGroup& vars) {
Expand All @@ -92,24 +92,12 @@ void writeFormRowsInto(String* out_str, const VariableGroup& vars) {
}
void writeFormTableInto(String* out_str, const VariableGroup& vars, const char* title,
const char* css_class) {
*out_str += "<table class=\"";
*out_str += css_class ? css_class : "readings";
*out_str +=
"\">\n"
"<thead><tr><th colspan=\"2\">";
*out_str += "<div id='l1' name='l1'>\n<fieldset>\n<legend><b>&nbsp; ";
escape(out_str, title ? title : vars.name());
*out_str +=
"</th></tr></thead>\n"
"<tbody>\n"
"<form method='post'>\n";
*out_str += " &nbsp;</b></legend><form method='post'>";
writeFormRowsInto(out_str, vars);
*out_str +=
"<tr><td colspan=\"2\"><button name='save' type='submit' class='button "
"bgrn'>Save</button></td></tr>\n";
*out_str += " </form>\n";
*out_str +=
"</tbody>\n"
"</table>\n";
*out_str += "</p><br/><button name='save' type='submit' class='button bgrn'>Save</button>\n";
*out_str += "</fieldset></form>\n";
}

} // namespace og3::html
2 changes: 1 addition & 1 deletion src/variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ BinarySensorVariable& BinarySensorVariable::operator=(bool value) {
String BoolVariable::formEntry() const {
auto radio = [this](const String& val, bool checked) -> String {
String id_val;
html::escape(&id_val, string().c_str());
html::escape(&id_val, name());
id_val += "_" + val;
return "<input id='" + id_val + "' name='" + name() + "' type='radio' value='" + val + "'" +
(checked ? " checked" : "") + "><label for='" + id_val + "'>" + val + "</label>";
Expand Down
1 change: 1 addition & 0 deletions src/web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const char html_page_template[] PROGMEM = R"====(<!DOCTYPE html>
<div style='text-align:right;font-size:10px;color: grey;'>
<hr>%FOOTER%</div>
</div>
</div>
</body>
</html>
)====";
Expand Down

0 comments on commit 195365e

Please sign in to comment.