Added support for FormValidator to IotWebConf

This commit is contained in:
Thomas Basler 2019-11-14 20:42:38 +01:00
parent 205e8a1c49
commit b857812bfe
2 changed files with 16 additions and 1 deletions

View File

@ -362,7 +362,11 @@ void IotWebConf::setConfigSavedCallback(std::function<void()> func)
this->_configSavedCallback = func; this->_configSavedCallback = func;
} }
#ifndef USE_ESPASYNCWEBSERVER
void IotWebConf::setFormValidator(std::function<boolean()> func) void IotWebConf::setFormValidator(std::function<boolean()> func)
#else
void IotWebConf::setFormValidator(std::function<boolean(AsyncWebServerRequest *request)> func)
#endif
{ {
this->_formValidator = func; this->_formValidator = func;
} }
@ -683,7 +687,11 @@ boolean IotWebConf::validateForm(AsyncWebServerRequest* request)
boolean valid = true; boolean valid = true;
if (this->_formValidator != NULL) if (this->_formValidator != NULL)
{ {
#ifndef USE_ESPASYNCWEBSERVER
valid = this->_formValidator(); valid = this->_formValidator();
#else
valid = this->_formValidator(request);
#endif
} }
// -- Internal validation. // -- Internal validation.

View File

@ -325,8 +325,11 @@ public:
* If the method will return false, the configuration will not be saved. * If the method will return false, the configuration will not be saved.
* Should be called before init()! * Should be called before init()!
*/ */
#ifndef USE_ESPASYNCWEBSERVER
void setFormValidator(std::function<boolean()> func); void setFormValidator(std::function<boolean()> func);
#else
void setFormValidator(std::function<boolean(AsyncWebServerRequest *request)> func);
#endif
/** /**
* Specify your custom Access Point connection handler. Please use IotWebConf::connectAp() as * Specify your custom Access Point connection handler. Please use IotWebConf::connectAp() as
* reference when implementing your custom solution. * reference when implementing your custom solution.
@ -531,7 +534,11 @@ private:
byte _apConnectionStatus = IOTWEBCONF_AP_CONNECTION_STATE_NC; byte _apConnectionStatus = IOTWEBCONF_AP_CONNECTION_STATE_NC;
std::function<void()> _wifiConnectionCallback = NULL; std::function<void()> _wifiConnectionCallback = NULL;
std::function<void()> _configSavedCallback = NULL; std::function<void()> _configSavedCallback = NULL;
#ifndef USE_ESPASYNCWEBSERVER
std::function<boolean()> _formValidator = NULL; std::function<boolean()> _formValidator = NULL;
#else
std::function<boolean(AsyncWebServerRequest* request)> _formValidator = NULL;
#endif
std::function<void(const char*, const char*)> _apConnectionHandler = std::function<void(const char*, const char*)> _apConnectionHandler =
&(IotWebConf::connectAp); &(IotWebConf::connectAp);
std::function<void(const char*, const char*)> _wifiConnectionHandler = std::function<void(const char*, const char*)> _wifiConnectionHandler =