Skip to content
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

While editing the numbers manually the incDecFactor is not considered. #23

Closed
Abhilash-Chandran opened this issue Aug 25, 2020 · 2 comments · Fixed by #30
Closed

While editing the numbers manually the incDecFactor is not considered. #23

Abhilash-Chandran opened this issue Aug 25, 2020 · 2 comments · Fixed by #30
Assignees
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@Abhilash-Chandran
Copy link
Owner

Abhilash-Chandran commented Aug 25, 2020

When editing the numbers, user are able to enter different number without getting affected by the increment decrement factor.
manual_edit

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 !
@Abhilash-Chandran
Copy link
Owner Author

Abhilash-Chandran commented Sep 4, 2020

Solution approach:

  1. Based on the min, max and incDecFactor decide whether the max value is inclusive or not.
  2. 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 :

  1. Calculate y = (x - min) % incDecFactor.
  2. If y==0 && x between min and max then x is valid don't change it.
  3. If y>0 then calculate a=x+y and b=x-y.
  4. If (a % incDecFactor) == 0 && a between min and max then x=a.
  5. Else apply rule 4 on b.
  6. If none step 1 through 5 is not satisfied raise a an error noting possible valid values.

@Abhilash-Chandran
Copy link
Owner Author

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.

  1. Evaluate if a stepMismatch occurs for the given input value.
  2. If yes then buildup alternative candidates and show error message.

@Abhilash-Chandran Abhilash-Chandran linked a pull request Jun 19, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant