-
-
Notifications
You must be signed in to change notification settings - Fork 245
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
oh-input: Fix editing a number item with unit and accept Enter key #3050
base: main
Are you sure you want to change the base?
Conversation
#2778 Bundle Size — 10.99MiB (+0.03%).57d5932(current) vs 95844d2 main#2743(baseline) Warning Bundle contains 2 duplicate packages – View duplicate packages Bundle metrics
Bundle size by type
Bundle analysis report Branch jimtng:ohinput-numeric Project dashboard Generated by RelativeCI Documentation Report issue |
In the sitemap UI, we went the extra mile to split of the unit in that case and show it separately behind the input field. Maybe it is worth looking at that. |
indeed, more work is needed here, so we can also see the unit. Some layout improvements would be nice too. |
5f11e46
to
04a7019
Compare
Will this respect the number of decimal positions from the state description? |
04a7019
to
a9d126d
Compare
@mherwege I've updated the first post above with the full detail of the changes + latest screenshot |
Display the number's unit after the input field for numeric type Make numeric input field right-aligned Improve input-elements alignment Accept Enter key to send the value, with or without a sendButton Honor useDisplayState config Signed-off-by: Jimmy Tanagra <[email protected]>
a9d126d
to
214c851
Compare
Where does the unit come from? If it is the item unit, that is meant to be for internal use, not representation. That will mix things again, while we separated them by introducing the item unit. The unit used should be from the state description. E.g. your unit is default (W) but you want to show and change in kW. |
Thanks! I'll make the adjustment.
Yes, but this needs to be done in core so it can perform unit conversion. The ui can't do that (or do we need to create a unit conversion REST endpoint?) Say the item's unit and stateDescription is |
Great. Sorry to go through iterations on this. My memory seems to come back in fragments. Can you also test with other locales that use , instead of . as the decimal separator? I believe that was the next challenge I ran into with basicUI. |
@mherwege This is a bit more complicated than it may seem. What do we do when the state description pattern is something like this:
![]() Note it contains two patterns, one with two decimal digits, the second one with two decimal digits. I believe we should use the last one for editing. I know this is a crazy pattern, but it is possible NOTE: it's already handled in my current code, but not yet pushed.
Thank you for sharing your experiences! Saves me from finding all these bugs later on down the line. I am still working through the above, and I'll incorporate your latest cases too. |
Yes, I am aware. I and also made an assumption there of only having on pattern. I also think there are places in core where it would fail when there is more than one. |
indeed, I believe there are many places that would get tripped up with this, in webui, basicui, too. Thankfully, I think I can rely on the fact that the unit is always the last token in the pattern, and that this isn't possible: |
Signed-off-by: Jimmy Tanagra <[email protected]>
27d797c
to
f7d3ea7
Compare
Signed-off-by: Jimmy Tanagra <[email protected]>
Finnish locale, amongst others, use a space as group (thousand) separator, whilst some others use comma / period for group separator / decimal and sometimes in reverse. Additionally... |
And then.... scientific notation Extracting the number to be edited out of displayState is not as straight forward as it may seem. It is fraught with many challenges when dealing with complex patterns. For example, I can have a pattern like this:
The Getting the raw number, then asking Core to convert it to the desired unit (and ignoring displayState completely) might be the cleanest, least hacky way I think. At the very least, we could still get the desired unit from displayState. @florian-h05 wdyt? |
As it is now, this PR will work fine provided that no funky patterns are used. i.e. no: numbers preceding the pattern not separated by space, no thousand separators, etc. |
Yes, I know this is tricky. In BasicUI, a few regex expressions are used for this:
I believe these do a fair job on , vs . and scientific notation. But they are not perfect. Spaces for thousand separators will fail, although it might be possible to add that.
I can't say what the problem is with that. Is that true for all browsers? When developing, I noticed there are some browser variations. Firefox seemed to be particularly challenging. |
Ideally, the numeric value converted to the display unit should just be part of the API response. But if I remember well the argument against it was it required adding extra fields in the SSE response. I don't think we want an extra REST call for each value to show in in input field. |
When oh-input is set to a Number item with unit, the f7-input in 'numeric' mode cannot set its numeric value to the item state because it contains the unit.
This PR:
min
andmax
configminimum
,maximum
, andstep
, they will be used as the default, but it can be overridden by the widget's configTest format %1$.4f and %1$.2f %unit%
. The last format specifier will be used.