ESPUI icon indicating copy to clipboard operation
ESPUI copied to clipboard

Min/Max values for Number controls are not working properly

Open az-z opened this issue 4 years ago • 7 comments

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. image

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);

az-z avatar Jun 26 '20 21:06 az-z

well... that might be an issue with how the html numberfield works... might need more investigation and testing, do you have a proposed solution ?

s00500 avatar Jun 29 '20 20:06 s00500

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 .

az-z avatar Jun 29 '20 21:06 az-z

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.

ericBcreator avatar Sep 27 '20 17:09 ericBcreator

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 .

az-z avatar Sep 27 '20 20:09 az-z

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...

s00500 avatar Oct 02 '20 16:10 s00500

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.

iangray001 avatar Jan 20 '22 22:01 iangray001

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.

aiotech-pub avatar Jan 04 '24 12:01 aiotech-pub