bootstrap-touchspin
bootstrap-touchspin copied to clipboard
Patch for situation in which max can be exceeded
I seem to have found a situation in which it is possible to exceed the specified max value by manually typing a value great than the maximum and then pressing the Enter key. I was unable to duplicate this behavior in the first example TouchSpin control on the demo page (which has a max of 100). However, the TouchSpin control on my page is doing something a bit different in that it captures change events on the TouchSpin input field and automatically updates the val of the input field of an ionRangeSlider control (which is supposed to stay in sync with the TouchSpin control). The ionRangeSlider control is similarly capturing onChange events and automatically updating the the val of the input field of the TouchSpin control. I think that's how it is bypassing the call to _checkValue() which would normally catch this situations and set the value to max.
I found a way to prevent this from happening by making one small change to the code of TouchSpin 3.0.1. At line 302 of bootstrap.touchspin.js I changed the event upon which _checkValue() is being called from 'blur' to 'change'.
So the code went from this:
originalinput.on('blur', function() { _checkValue(); });
To this:
originalinput.on('change', function() { _checkValue(); });
Of course, the downside is that this will result in _checkValue() getting called a lot more. However, it doesn't noticeably affect the responsiveness of the TouchSpin control for me on my laptop.
I submit this small change for consideration as a patch to TouchSpin 3.0.1.
Thanks for all your great work on TouchSpin!