Add option to reverse checkbox and label order

pull/99/head
Arjan Mels 6 years ago
parent a56ce43d8f
commit 0046300733
  1. 2
      src/AutoConnectDefs.h
  2. 1
      src/AutoConnectElementBasis.h
  3. 10
      src/AutoConnectElementBasisImpl.h
  4. 4
      src/AutoConnectElementJson.h
  5. 5
      src/AutoConnectElementJsonImpl.h

@ -11,7 +11,7 @@
#define _AUTOCONNECTDEFS_H_ #define _AUTOCONNECTDEFS_H_
// Uncomment the following AC_DEBUG to enable debug output. // Uncomment the following AC_DEBUG to enable debug output.
#define AC_DEBUG // #define AC_DEBUG
// Debug output destination can be defined externally with AC_DEBUG_PORT // Debug output destination can be defined externally with AC_DEBUG_PORT
#ifndef AC_DEBUG_PORT #ifndef AC_DEBUG_PORT

@ -109,6 +109,7 @@ class AutoConnectCheckboxBasis : virtual public AutoConnectElementBasis {
String label; /**< A label for a subsequent input box */ String label; /**< A label for a subsequent input box */
bool checked; /**< The element should be pre-selected */ bool checked; /**< The element should be pre-selected */
bool labelFirst; /**< Output label before the checkbox */
}; };
/** /**

@ -62,12 +62,14 @@ const String AutoConnectCheckboxBasis::toHTML(void) const {
String html = String(""); String html = String("");
if (enable) { if (enable) {
html = String(F("<input type=\"checkbox\" name=\"")) + name + String(F("\" value=\"")) + value + String("\""); if (labelFirst && label.length())
html += String(F("<label for=\"")) + name + String(F("\">")) + label + String(F("</label>"));
html += String(F("<input type=\"checkbox\" name=\"")) + name + String(F("\" value=\"")) + value + String("\"");
if (checked) if (checked)
html += String(F(" checked")); html += String(F(" checked"));
if (label.length()) html += String(F(" id=\"")) + name + String(F("\">"));
html += String(F(" id=\"")) + name + String(F("\"><label for=\"")) + name + String("\">") + label + String(F("</label")); if (!labelFirst && label.length())
html += String(">"); html+=String(F("<label for=\"")) + name + String("\">") + label + String(F("</label>"));
html = AutoConnectElementBasis::posterior(html); html = AutoConnectElementBasis::posterior(html);
} }
return html; return html;

@ -24,6 +24,7 @@
#define AUTOCONNECT_JSON_KEY_OPTION "option" #define AUTOCONNECT_JSON_KEY_OPTION "option"
#define AUTOCONNECT_JSON_KEY_PATTERN "pattern" #define AUTOCONNECT_JSON_KEY_PATTERN "pattern"
#define AUTOCONNECT_JSON_KEY_PLACEHOLDER "placeholder" #define AUTOCONNECT_JSON_KEY_PLACEHOLDER "placeholder"
#define AUTOCONNECT_JSON_KEY_LABELFIRST "labelfirst"
#define AUTOCONNECT_JSON_KEY_POSTERIOR "posterior" #define AUTOCONNECT_JSON_KEY_POSTERIOR "posterior"
#define AUTOCONNECT_JSON_KEY_SELECTED "selected" #define AUTOCONNECT_JSON_KEY_SELECTED "selected"
#define AUTOCONNECT_JSON_KEY_STORE "store" #define AUTOCONNECT_JSON_KEY_STORE "store"
@ -162,11 +163,12 @@ class AutoConnectButtonJson : public AutoConnectElementJson, public AutoConnectB
*/ */
class AutoConnectCheckboxJson : public AutoConnectElementJson, public AutoConnectCheckboxBasis { class AutoConnectCheckboxJson : public AutoConnectElementJson, public AutoConnectCheckboxBasis {
public: public:
explicit AutoConnectCheckboxJson(const char* name = "", const char* value = "", const char* label = "", const bool checked = false, const ACPosterior_t post = AC_Tag_BR) { explicit AutoConnectCheckboxJson(const char* name = "", const char* value = "", const char* label = "", const bool checked = false, const bool labelFirst = false, const ACPosterior_t post = AC_Tag_BR) {
AutoConnectCheckboxBasis::name = String(name); AutoConnectCheckboxBasis::name = String(name);
AutoConnectCheckboxBasis::value = String(value); AutoConnectCheckboxBasis::value = String(value);
AutoConnectCheckboxBasis::label = String(label); AutoConnectCheckboxBasis::label = String(label);
AutoConnectCheckboxBasis::checked = checked; AutoConnectCheckboxBasis::checked = checked;
AutoConnectCheckboxBasis::labelFirst = String(labelFirst);
AutoConnectCheckboxBasis::post = post; AutoConnectCheckboxBasis::post = post;
_defaultPost = AC_Tag_BR; _defaultPost = AC_Tag_BR;
} }

@ -139,7 +139,7 @@ void AutoConnectButtonJson::serialize(JsonObject& json) {
*/ */
size_t AutoConnectCheckboxJson::getObjectSize(void) const { size_t AutoConnectCheckboxJson::getObjectSize(void) const {
size_t size = AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(2); size_t size = AutoConnectElementJson::getObjectSize() + JSON_OBJECT_SIZE(2);
size += sizeof(AUTOCONNECT_JSON_KEY_LABEL) + label.length() + 1 + sizeof(AUTOCONNECT_JSON_KEY_CHECKED); size += sizeof(AUTOCONNECT_JSON_KEY_LABEL) + label.length() + 1 + sizeof(AUTOCONNECT_JSON_KEY_CHECKED) + sizeof(AUTOCONNECT_JSON_KEY_LABELFIRST);
return size; return size;
} }
@ -157,6 +157,8 @@ bool AutoConnectCheckboxJson::loadMember(const JsonObject& json) {
label = json[F(AUTOCONNECT_JSON_KEY_LABEL)].as<String>(); label = json[F(AUTOCONNECT_JSON_KEY_LABEL)].as<String>();
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_CHECKED))) if (json.containsKey(F(AUTOCONNECT_JSON_KEY_CHECKED)))
checked = json[F(AUTOCONNECT_JSON_KEY_CHECKED)].as<bool>(); checked = json[F(AUTOCONNECT_JSON_KEY_CHECKED)].as<bool>();
if (json.containsKey(F(AUTOCONNECT_JSON_KEY_LABELFIRST)))
labelFirst = json[F(AUTOCONNECT_JSON_KEY_LABELFIRST)].as<bool>();
return true; return true;
} }
return false; return false;
@ -173,6 +175,7 @@ void AutoConnectCheckboxJson::serialize(JsonObject& json) {
json[F(AUTOCONNECT_JSON_KEY_VALUE)] = value; json[F(AUTOCONNECT_JSON_KEY_VALUE)] = value;
json[F(AUTOCONNECT_JSON_KEY_LABEL)] = label; json[F(AUTOCONNECT_JSON_KEY_LABEL)] = label;
json[F(AUTOCONNECT_JSON_KEY_CHECKED)] = checked; json[F(AUTOCONNECT_JSON_KEY_CHECKED)] = checked;
json[F(AUTOCONNECT_JSON_KEY_LABELFIRST)] = labelFirst;
} }
/** /**

Loading…
Cancel
Save