tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.46k stars 1.94k forks source link

Can Add boolean parameters! #629

Open ideaChenGo opened 6 years ago

ideaChenGo commented 6 years ago

134

Hello Could you make the PR to show how you solved your task? I think that boolean parameters at the configuration portal will be useful for others. Yeas, we have an ability to add custom html and css, but it would be ok to have also the default way to make basic html objects/labels/radiobuttons/etc (like in Twitter Bootstrap).

I think, boolean parameters with radiobuttons could be look like these: idea

And it seems to be ok to add a type of form label for custom parameters like:

// id/name, placeholder/prompt, type, default, length

WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "label", mqtt_server, 40);
wifiManager.addParameter(&custom_mqtt_server);
WiFiManagerParameter custom_dht22_param("dht22", "dht22 on", "radio_button", dht22, 20);
wifiManager.addParameter(&custom_dht22_param);
WiFiManagerParameter custom_ds18b20_param("ds18b20", "ds18b20 on", "radio_button", ds18b20, 20);
wifiManager.addParameter(&custom_ds18b20_param)

Maybe it needs to make a new handler for these inputs to store data depends on element type (e.g. store boolean in json for radiobutton elements).

what do you think?

ideaChenGo commented 6 years ago

fngstudios commented on 11 Aug 2017 sorry ,i begin use github,no idea @fngstudios . just copy to here. This is what I did for the bool parameters:Added the getType method to WiFiManagerParameter and modifyed the constructor: WiFiManagerParameter::WiFiManagerParameter(const char id, const char placeholder, const char *defaultValue, int length,bool isBoolean) { .._isBoolean = isBoolean;. } bool WiFiManagerParameter::getType(){return _isBoolean;}

Then when you render the parameters: // add the extra parameters to the form for (int i = 0; i < _paramsCount; i++) { if (_params[i] == NULL) {break;} if (!_params[i]->getType()){ String pitem = FPSTR(HTTP_FORM_PARAM); pitem.replace("{i}", _params[i]->getID()); pitem.replace("{n}", _params[i]->getID()); pitem.replace("{p}", _params[i]->getPlaceholder());snprintf(parLength, 2, "%d", _params[i]->getValueLength()); pitem.replace("{l}", parLength);pitem.replace("{v}", _params[i]->getValue());page += pitem; }else{ String pitem = FPSTR(HTTP_FORM_BOOL_PARAM); pitem.replace("{i}", _params[i]->getID()); pitem.replace("{n}", _params[i]->getID()); pitem.replace("{p}", _params[i]->getPlaceholder());snprintf(parLength, 2, "%d", _params[i]->getValueLength()); pitem.replace("{l}", parLength); if (_params[i]->getValue()){ pitem.replace("{c}", "checked"); }else{ pitem.replace("{c}", ""); } page += pitem; }}

And in the .h: const char HTTP_FORM_BOOL_PARAM[] PROGMEM = "{p}<input type='checkbox' id='{i}' name='{n}' length='{l}' value='1' {c}>";

tablatronix commented 5 years ago

If we can make it as easy as adding "type" then maybe

dddhhhrrr commented 5 years ago

This would be really REALLY useful, is there any plan on adding something like this?