While editing the numbers manually the incDecFactor is not considered.
Abhilash-Chandran opened this issue · comments
When editing the numbers, user are able to enter different number without getting affected by the increment decrement factor.
As @abulka mentioned in another discussion:
- A relaxed interpretation of what should happen would be that the user can enter anything in range, and the inc/dec works off that.
- The other interpretation is that whatever the user enters is corrected to be a multiple of the inc/dec factor based off the min. This is bit trickier and also relies on correct settings of the min/max/inc widget values to be fully self consistent. For example I could set up min: -1 max: 4 inc: 2 and never be able to get to 4. I could enter 4 manually and it would auto-correct to a multiple of the inc. factor starting from min, which would be 3. The user might not be so happy, since the max is 4 !
Solution approach:
- Based on the
min
,max
andincDecFactor
decide whether themax
value is inclusive or not. - Always round the manually entered value to the nearest allowed number.
Case-1:
min
= 1, max
=5 and incDecFactor
=2.
* In this case the allowed values will be 1, 3 and 5.
* Includes the max value 5.
Case-2:
min
= 1, max
=6 and incDecFactor
=2.
* In this case the allowed values will be 1, 3 and 5.
* Excludes the max value 6.
Case-3:
min
= 1, max
=3 and incDecFactor
=0.5.
* In this case the allowed values will be 1, 1.5, 2, 2.5 and 3.
* Includes the max value 3.
Case-4:
min
= 1, max
=2.75 and incDecFactor
=0.5.
* In this case the allowed values will be 1, 1.5, 2 and 2.5.
* Excludes the max value 2.75.
This can implemented with the following equation and validate the input.
Given a user enters a value say x
:
- Calculate
y = (x - min) % incDecFactor
. - If
y==0 && x between min and max
thenx
is valid don't change it. - If
y>0
then calculatea=x+y
andb=x-y
. - If
(a % incDecFactor) == 0 && a between min and max
thenx=a
. - Else apply rule 4 on b.
- If none step 1 through 5 is not satisfied raise a an error noting possible valid values.
Found a better approach to address this. This is based on the HTML input type=number implementation of chrome. The logic is spread across multiple files.
- Evaluate if a stepMismatch occurs for the given input value.
- If yes then buildup alternative candidates and show error message.