-
Notifications
You must be signed in to change notification settings - Fork 159
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
Behaviour is not exactly like the native input[type='number'] #56
Comments
The |
|
In my opinion the correct behaviour is not, that ist should step to |
Interesting, but if I read the specs correctly with the quote you added (I also added it just below), I think doing
The key here is the beginning : In the example above, entering manually While this logic would be good to implement in the EDIT : As the quote says, "the user agent may round to the nearest valid value" : in chrome, this is not what happens ; instead, it allows the value, but when submitting a form, it will not pass validation, providing a message saying something like "The nearest valid values are 1 and 11". The browser really dictates this behavior, but IMO, I would prefer that it round automatically. |
Okay, but wee agree, that it should work like the native spinner, or not? I created a test page for this with different parameters: https://shaack.com/projekte/bootstrap-input-spinner/test-native.html |
Oh, I completely agree that it should work like the native spinner! Although I added in my latest edit that it is also broswer (well, user-agent...) dependant, so unless you want to add a check for the user-agent and implement the logic of every browser, I think we should agree on what would be the best default behavior "of a native spinner". I don't especially like how Chrome does it : if a user enters a value manually, that value is validated only on form submit - wouldn't it be better if the validation happens when the user entered a value? With all I said above, I'm trying to think of what would be the default behavior if you entered then With that said, the default should probably be to test only for the value on form submit? If so, we could simply use the What do you think? |
With the removal of the On changing value manually (not with the buttons), your plugin would check the validity and if it isn't, we would use the I've searched a bit and there is the validation message as a property in the javascript's object : If I based this on Chrome's behavior, this would mean that bad manual inputs stays as is in the input, but gets invalidated (so forms would show the validation message on submit) : the value wouldn't change when typing it / losing focus. Using the buttons would jump to the nearest value in the direction of the button. I could draft an implementation of this, but doing it as Chrome does means that while it is based on a majority of the user base, there might be edge cases where some users may feels like not really native (for example, if Opera actually handles these inputs between steps and rounds them when losing the focus of the input, then my suggestion's implementation will be a bit different. this is an example, I don't know how Opera handles it, probably the same as Chrome as Opera is Chrome based). @shaack would it be an accepted default? |
Should work as described here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#step Should implement: "Only values which are equal to the basis for stepping (min if specified, value otherwise, and an appropriate default value if neither of those is provided) are valid." and "Note: When the data entered by the user doesn't adhere to the stepping configuration, the user agent may round to the nearest valid value, preferring numbers in the positive direction when there are two equally close options." |
The issue is still there :
The issue I had was about, for example, Chrome implementing the rounding, while Safari wouldn't. I didn't do an exhaustive list of which browsers (read: user agent) implement the stepping mechanism in the way Chrome does or not, but the issue is that if you want to have a spinner that behaves natively, you'll need to do user agent checks and implements all the different implementations of these different user agents. Obviously, you could go for the route of implementing the way Chrome does it, and force it out like so, maybe even implement no rounding as well and add a config option so developers who uses your spinner will have the choice - there's many things you could do, but a decision needs to be made here :
Some of those options require more job than the others, and I don't want to be the judge of this : I think I'd rather do one consistent behavior for the plugin, but having a native feel for the spinner is interesting too, so I'm torn between those options... |
Yes, many thanks for the summary. I think it should behave like native, like the Chrome browser. |
For a quick test, simply set
data-step="2"
, set the value to5
, and try to decrement : expected3
, got2
. You can also do this test in your live demo in your "Dynamically handling of min, max, step and data-decimals" section (sidenote : would be nice if there was ids to your page sections, so we could link them directly in links!).Same goes with increment, incrementing an odd number by an even number does not give the expected result (with the last example, I would expect
5 + 2 =
7
, but8
is currently being produced).I realized that by doing some tests on my own fork, and tracing back I found that you changed to a rounding logic in this commit : be6b7c8, and now I'm wondering what is that "better form handling".
A fix for this would be to change this line :
bootstrap-input-spinner/src/bootstrap-input-spinner.js
Line 196 in 5848e20
to :
... but I figure there was an issue to doing simply that, as this is what you had previously... so here's an issue to discuss about it :)
The text was updated successfully, but these errors were encountered: