ESPUI
ESPUI copied to clipboard
Min/Max values for Number controls are not working properly
Describe the bug as described in #79 and #82 the proper way to add min/max to the number control is to https://github.com/s00500/ESPUI/issues/79#issuecomment-643675938
And that works fine_if_ you use number field controls ( arrows) to change the value. BUT, any value can be added to the field and, subsequently passed down the system, by just typing it (value) into the control box.
Expected behavior user can not enter just any value. only number and only within the specified range.
Screenshots
If applicable, add screenshots to help explain your problem.
Code:
sample_freq_control = ESPUI.addControl( ControlType::Number, "Sampling Frequency (min):", String(config.TH_measure_interval), ControlColor::Alizarin, tab2, &numberCallBack);
ESPUI.addControl(ControlType::Min, "Sampling Frequency (min):", String(20), ControlColor::None, sample_freq_control);
ESPUI.addControl(ControlType::Max, "Sampling Frequency (min):", String(90), ControlColor::None, sample_freq_control);
well... that might be an issue with how the html numberfield works... might need more investigation and testing, do you have a proposed solution ?
well... that might be an issue with how the html numberfield works... might need more investigation and testing, do you have a proposed solution ?
nope :( . I'd think that some kind of jscript might need to be added .
My suggestion would be to just validate the numbers with the callback function - i.e. constrain(value, min, max) - and ditch the min/max controls. It saves resources for 2 controls as well.
That is how i do it now. Ideally the type and value validation belongs to library.
On Sun, Sep 27, 2020, 13:57 ericBcreator [email protected] wrote:
My suggestion would be to just validate the numbers with the callback function - i.e. constrain(value, min, max) - and ditch the min/max controls. It saves resources for 2 controls as well.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/s00500/ESPUI/issues/84#issuecomment-699666737, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGHHXOBLINBOQ3HC6C47ODSH54G3ANCNFSM4OJV7B4A .
well... user input can never be trusted, so the real ideal thing is having both sides check it =P
you could try to write a simple js function that hooks on the onchange event and checks against min and max maybe, but i think it is a little difficult to build a nice system without expanding the js quite a bit...
Indeed. This is how HTML number input
's work. The limits are applied correctly.
As Lukas correctly notes, regardless of what happens in the UI the numbers should be validated on the ESP because the user can send anything they like (even things that aren't numbers!). I've switched this from a Bug
to Feature Request
because I'll consider if there is a way that the UI could be improved to help the user.
Is there a way to access Min and Max of a numeric input type or any other control that supports it? If there is no way to access them I would request to add a couple of methods to do that, it would simplify validation data processing.