Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes some small API changes to the
WiFiManagerParameter
class to improve clarity, usability, and encapsulation:Length to Max Length
length
arguments have been changed tomaxLength
getValueLength()
has been changed togetValueMaxLength()
When used as an argument, this refers to the max length of the form and the size of the internal buffer, not the length of the string passed as an argument as expected.
Similarly, the value returned is the max length of the form and the size of the internal buffer, not the length of the value stored.
The internal name (
_length
) has not been changed to maintain compatibility with user code, as it's exposed as a protected value. This should be changed in the next major version.ID to Name
getID()
has been changed togetName()
In HTML forms, names and IDs are two different attributes. Although this value is applied to both, when submitted 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 internally.
The internal name (
_id
) has not been changed to maintain compatibility with user code, as it's exposed as a protected value. This should be changed in the next major version.Value Received Function
setValueReceived()
function to receive data from the serverCurrently the user can set the parameter value and max length via the
setValue(const char *defaultValue, int maxLength)
function, and inWiFiManager::doParamSave()
the server sets the value directly to the buffer pointer using the existing max length.This function provides a standardized way for the server (and any user code) to set a new value while respecting the existing max length value. This is also virtual, so derived parameter classes can intercept the received value and perform additional logic or sanitization if necessary.
WiFiManager friendship removed
There is no reason for the
WiFiManager
class to have a friendship with the parameter class. The internal calls have been replaced with the corresponding public functions and the friendship has been removed.Incidental Bugfixes
setValue()
now checks if a max length argument is negativeWiFiManagerParameter
's destructor is now virtualAlthough PR contains API changes there should be no breaking changes. The few items marked deprecated should be removed on the next major release.
If this is merged, here are the changes to make on the next major release:
WiFiManagerParameter::_length
should be refactored to_maxLength
WiFiManagerParameter::getValueLength() const
should be removedWiFiManagerParameter::_id
should be refactored to_name
WiFiManagerParameter::getID() const
should be removedThis is a reworked version of PR #1772 that will serve as a basis for other
WiFiManagerParameter
related PRs.