Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFiManagerParameter Encapsulated HTML Generation #1774

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

dmadison
Copy link

This PR encapsulates the WiFiManagerParameter HTML generation as part of the class, rather than as a function within WiFiManager. This allows derived classes to define their own HTML output and greatly increases encapsulation:

 virtual String getHTML() const;

This also greatly simplifies the getParamOut() function of WiFiManager:

...
    // add the extra parameters to the form
    for (int i = 0; i < _paramsCount; i++) {
      page += _params[i]->getHTML();
    }
...

This is a non-breaking change and should not modify the output HTML, with the exception of {I} as noted below.


Note that this PR contains a potentially breaking change, by removing token I (T_I / {I} / capital 'i') processing for parameters which include that token in their string. This was removed because the parameter HTML is no longer generated in the context of the loop, and I didn't see a compelling reason to pass the iterator to the class function.

From what I can see parsing through the history of the strings_en file that feature was never used by the library itself, but it could potentially affect a user somewhere with custom string files (HTTP_FORM_LABEL / HTTP_FORM_PARAM). If that's objectionable I'm happy to revert that commit (c4665fc).

Please note that this PR incorporates the necessary API changes from #1773.

This does *not* refer to the length of the string passed in, or the length of the string currently stored. This refers to the maximum length of the HTML form, and the size of the class buffer to hold the value.

Note that this does *not* change the internal _length name, because the variable is exposed as protected and through friendship with WiFiManager. It is however marked deprecated and can be changed on the next major release.
To clarify that the function returns the *max* possible length, and not the length of the current value.

Deprecating getValueLength for removal on next major release.
In HTML forms names and IDs are two different things. Although this value is applied to both attributes, the form data corresponds to the name, *not* the ID. This causes confusion if we want the name and ID to differ, since we are currently calling the name the ID.
For intercepting the value received from the server in derived classes
Preventing a new default value from being assigned if the max length is set to a negative value
Because this is polymorphic, the destructor needs to be virtual to allow for properly clearing data
This creates better encapsulation, and allows it to be overridden by child classes.
This is unused and awkward because it must be done within the manager class to use the loop parameter, since passing the loop value to the parameter object would be odd. Removing it makes the most sense, although it is technically a breaking change if the user has custom string files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant