mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-17 00:21:31 +10:00
parameter label
This commit is contained in:
+25
-7
@@ -17,22 +17,23 @@ WiFiManagerParameter::WiFiManagerParameter(const char *custom) {
|
||||
_placeholder = NULL;
|
||||
_length = 0;
|
||||
_value = NULL;
|
||||
|
||||
_labelPlacement = WFM_LABEL_BEFORE;
|
||||
_customHTML = custom;
|
||||
}
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) {
|
||||
init(id, placeholder, defaultValue, length, "");
|
||||
init(id, placeholder, defaultValue, length, "", WFM_LABEL_BEFORE);
|
||||
}
|
||||
|
||||
WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) {
|
||||
init(id, placeholder, defaultValue, length, custom);
|
||||
init(id, placeholder, defaultValue, length, custom, WFM_LABEL_BEFORE);
|
||||
}
|
||||
|
||||
void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) {
|
||||
void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) {
|
||||
_id = id;
|
||||
_placeholder = placeholder;
|
||||
_length = length;
|
||||
_labelPlacement = labelPlacement;
|
||||
_value = new char[length + 1];
|
||||
for (int i = 0; i < length; i++) {
|
||||
_value[i] = 0;
|
||||
@@ -56,6 +57,9 @@ const char* WiFiManagerParameter::getPlaceholder() {
|
||||
int WiFiManagerParameter::getValueLength() {
|
||||
return _length;
|
||||
}
|
||||
int WiFiManagerParameter::getLabelPlacement() {
|
||||
return _labelPlacement;
|
||||
}
|
||||
const char* WiFiManagerParameter::getCustomHTML() {
|
||||
return _customHTML;
|
||||
}
|
||||
@@ -115,8 +119,7 @@ void WiFiManager::setupConfigPortal() {
|
||||
server->on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this));
|
||||
server->on("/i", std::bind(&WiFiManager::handleInfo, this));
|
||||
server->on("/r", std::bind(&WiFiManager::handleReset, this));
|
||||
//server->on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check.
|
||||
server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
|
||||
//server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
|
||||
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));
|
||||
server->begin(); // Web server start
|
||||
DEBUG_WM(F("HTTP server started"));
|
||||
@@ -471,7 +474,22 @@ void WiFiManager::handleWifi(boolean scan) {
|
||||
break;
|
||||
}
|
||||
|
||||
String pitem = FPSTR(HTTP_FORM_PARAM);
|
||||
//String pitem = FPSTR(HTTP_FORM_PARAM);
|
||||
String pitem;
|
||||
switch (_params[i]->getLabelPlacement()) {
|
||||
case WFM_LABEL_BEFORE:
|
||||
pitem = FPSTR(HTTP_FORM_LABEL);
|
||||
pitem += FPSTR(HTTP_FORM_PARAM);
|
||||
break;
|
||||
case WFM_LABEL_AFTER:
|
||||
pitem = FPSTR(HTTP_FORM_PARAM);
|
||||
pitem += FPSTR(HTTP_FORM_LABEL);
|
||||
break;
|
||||
default:
|
||||
// WFM_NO_LABEL
|
||||
pitem = FPSTR(HTTP_FORM_PARAM);
|
||||
break;
|
||||
}
|
||||
if (_params[i]->getID() != NULL) {
|
||||
pitem.replace("{i}", _params[i]->getID());
|
||||
pitem.replace("{n}", _params[i]->getID());
|
||||
|
||||
@@ -29,6 +29,7 @@ const char HTTP_HEAD_END[] PROGMEM = "</head><body><div style='text-align
|
||||
const char HTTP_PORTAL_OPTIONS[] PROGMEM = "<form action=\"/wifi\" method=\"get\"><button>Configure WiFi</button></form><br/><form action=\"/0wifi\" method=\"get\"><button>Configure WiFi (No Scan)</button></form><br/><form action=\"/i\" method=\"get\"><button>Info</button></form><br/><form action=\"/r\" method=\"post\"><button>Reset</button></form>";
|
||||
const char HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a> <span class='q {i}'>{r}%</span></div>";
|
||||
const char HTTP_FORM_START[] PROGMEM = "<form method='get' action='wifisave'><input id='s' name='s' length=32 placeholder='SSID'><br/><input id='p' name='p' length=64 type='password' placeholder='password'><br/>";
|
||||
const char HTTP_FORM_LABEL[] PROGMEM = "<label for=\"{i}\">{p}</label>";
|
||||
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' length={l} placeholder='{p}' value='{v}' {c}>";
|
||||
const char HTTP_FORM_END[] PROGMEM = "<br/><button type='submit'>save</button></form>";
|
||||
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><div class=\"c\"><a href=\"/wifi\">Scan</a></div>";
|
||||
@@ -37,25 +38,33 @@ const char HTTP_END[] PROGMEM = "</div></body></html>";
|
||||
|
||||
#define WIFI_MANAGER_MAX_PARAMS 10
|
||||
|
||||
#define WFM_LABEL_BEFORE 1
|
||||
#define WFM_LABEL_AFTER 2
|
||||
#define WFM_NO_LABEL 0
|
||||
|
||||
class WiFiManagerParameter {
|
||||
public:
|
||||
WiFiManagerParameter(const char *custom);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
|
||||
WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement);
|
||||
|
||||
const char *getID();
|
||||
const char *getValue();
|
||||
const char *getPlaceholder();
|
||||
int getValueLength();
|
||||
int getLabelPlacement();
|
||||
const char *getCustomHTML();
|
||||
private:
|
||||
const char *_id;
|
||||
const char *_placeholder;
|
||||
char *_value;
|
||||
int _length;
|
||||
int _labelPlacement;
|
||||
const char *_customHTML;
|
||||
|
||||
void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom);
|
||||
void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement);
|
||||
|
||||
friend class WiFiManager;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user