Dcumentation for fetchElement function

pull/110/head
Hieromon Ikasamo 5 years ago
parent 0bfa63a388
commit 1d8cb4b33e
  1. 1
      README.md
  2. 55
      mkdocs/achandling.md
  3. 7
      mkdocs/apiaux.md
  4. 1
      mkdocs/changelog.md

@ -101,6 +101,7 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some
- Supports that `<br>` tags can now be added to each element. (PR #95) - Supports that `<br>` tags can now be added to each element. (PR #95)
- Supports that able to place the checkbox label forward or backward. (PR #99) - Supports that able to place the checkbox label forward or backward. (PR #99)
- Supports flicker signal output according to the status of WiFi_mode. (issue #98) - Supports flicker signal output according to the status of WiFi_mode. (issue #98)
- Supports AutoConnectAux::fetchElement function to retrieve inputted element values via a custom Web page.
- Fixed bug in AutoConnectCredential when offset is >256. (PR #103) - Fixed bug in AutoConnectCredential when offset is >256. (PR #103)
### [0.9.10] June 12, 2019 ### [0.9.10] June 12, 2019

@ -595,6 +595,61 @@ portal.on("/echo", [](AutoConnectAux& aux, PageArgument& args) {
portal.begin(); portal.begin();
``` ```
### <i class="fa fa-wrench"></i> Retrieve the values with WebServer::on handler
ESP8266WebServer class and the WebServer class assume that the implementation of the ReqestHandler class contained in the WebServer library will handle the URL requests. Usually, it is sketch code registered by ESP8266WebServer::on function.
When the page transitions from the custom Web page created by AutoConnectAux to the handler registered by ESP2866WebServer::on function, a little trick is needed to retrieve the values of AutoConnectElements. (i.e. the URI of the ESP8266WebServer::on handler is specified in the [uri](acelements.md#uri) attribute of [AutoConnectSubmit](acelements.md#autoconnectsubmit)) AutoConnect cannot intervene in the procedure in which the ESP8266WebServer class calls the on-page handler by the sketch. Therefore, it is necessary to retrieve preliminary the values of AutoConnectElements using the [AutoConnectAux::fetchElement](apiaux.md#fetchelement) function for value processing with the on-page handler.
The following sketch is an example of extracting values inputted on a custom web page with an on-page handler and then processing it.
```cpp hl_lines="13 20 27 38"
ESP8266WebServer server;
AutoConnect portal(server);
AutoConnectAux Input;
const static char InputPage[] PROGMEM = R"r(
{
"title": "Input", "uri": "/input", "menu": true, "element": [
{ "name": "input", "type": "ACInput", "label": "INPUT" },
{
"name": "save",
"type": "ACSubmit",
"value": "SAVE",
"uri": "/"
}
]
}
)r";
// An on-page handler for '/' access
void onRoot() {
String content =
"<html>"
"<head><meta name='viewport' content='width=device-width, initial-scale=1'></head>"
"<body><div>INPUT: {{value}}</div></body>"
"</html>";
Input.fetchElement(); // Preliminary acquisition
// For this steps to work, need to call fetchElement function beforehand.
String value = Input["input"].value;
content.replace("{{value}}", value);
server.send(200, "text/html", content);
}
void setup() {
Input.load(InputPage);
portal.join(Input);
server.on("/", onRoot); // Register the on-page handler
portal.begin();
}
void loop() {
portal.handleClient();
}
```
### <i class="fa fa-wpforms"></i> Overwrite the AutoConnectElements ### <i class="fa fa-wpforms"></i> Overwrite the AutoConnectElements
Sketches can update the attributes of AutoConnectElements with two approaches. A one is to assign directly to the attributes of a member variable of its element. The other is to overwrite them with loading the element by [AutoConnectAux::loadElement](apiaux.md#loadelement). Sketches can update the attributes of AutoConnectElements with two approaches. A one is to assign directly to the attributes of a member variable of its element. The other is to overwrite them with loading the element by [AutoConnectAux::loadElement](apiaux.md#loadelement).

@ -42,6 +42,13 @@ Add an element to the AutoConnectAux. An added element is displayed on the custo
<dd><span class="apidef">addons</span><span class="apidesc">An array list of reference of AutoConnectElements. The [list initialization](https://en.cppreference.com/w/cpp/language/list_initialization) with braced-init-list of the [std::vector](https://en.cppreference.com/w/cpp/container/vector) can be used for the addons parameter cause the actual definition of type **AutoConnectElementVT** is `std::vector<std::reference_wrapper<AutoConnectElement>>`.</span></dd> <dd><span class="apidef">addons</span><span class="apidesc">An array list of reference of AutoConnectElements. The [list initialization](https://en.cppreference.com/w/cpp/language/list_initialization) with braced-init-list of the [std::vector](https://en.cppreference.com/w/cpp/container/vector) can be used for the addons parameter cause the actual definition of type **AutoConnectElementVT** is `std::vector<std::reference_wrapper<AutoConnectElement>>`.</span></dd>
</dl> </dl>
### <i class="fa fa-caret-right"></i> fetchElement
```cpp
void fetchElement(void)
```
Retrieve the values of the AutoConnectElements on the custom Web page. Refer to [how to use the fetchElement](achandling.md#retrieve-the-values-with-webserveron-handler).
### <i class="fa fa-caret-right"></i> getElement ### <i class="fa fa-caret-right"></i> getElement
```cpp ```cpp

@ -3,6 +3,7 @@
- Supports that `<br>` tags can now be added to each element. - Supports that `<br>` tags can now be added to each element.
- Supports that able to place the checkbox label forward or backward. - Supports that able to place the checkbox label forward or backward.
- Supports flicker signal output according to the status of WiFi_mode. - Supports flicker signal output according to the status of WiFi_mode.
- Supports [**AutoConnectAux::fetchElement**](apiaux.md#fetchelement) function to retrieve inputted element values via a custom Web page.
- Fixed bug in AutoConnectCredential when offset is >256. - Fixed bug in AutoConnectCredential when offset is >256.
#### [0.9.10] June 12, 2019 #### [0.9.10] June 12, 2019

Loading…
Cancel
Save