auto_numeric_js
auto_numeric_js copied to clipboard
Feature Request: denominators/multiplers
It would be good if the widget could accept certain keystrokes and use them as multiplers. For example "2m" should be converted to two million (2000000). 3b to 3 billion, 4k to 4000, etc etc.
I imagine it could be a optional parameter like this:
$('#someinput').autoNumeric({multipliers: {'k': 1000, 'm': 1000000, 'b': 1000000000}});
I had a look at the code and this seems tricky. There's lots there to stop extraneous chars from coming into the input at all, and then other code that handles pasted values, etc. I'd like to contribute but would appreciate from pointers on changes that would be required, etc.
Another, more general approach could be to allow callbacks after the value has changed. The receiver would accept the actual numeric value, plus suffixes (and prefixes I guess) and can then compute a new number to be returned to autoNumeric. Something like:
var customHandler = function(elem, val, prefix, suffix){
// do stuff in here
// elem is the DOM element
// val has the numeric value after all stripping and unformatting
// prefix has chars stripped off the front
// suffix has the chars stripped off the end
return val * 1;
}
$('#someinput').autoNumeric({onChange: customHandler()});
It also occurs to me that this callback approach would be useful for implementing min/max values that depend on other page elements, rather than initial widget setup. There are probably many other uses.
Robert,
Thank you for your interest and offer to help.
Before you jump in you may want to look at the latest version I have been working on (http://www.decorplanit.com/plugin/autoNumeric-1.8.0.htm). It does not have the feature you are suggesting but has many other enhancements. I am just finishing the documentation so the option code is not yet working.
Your comments and suggestions are welcomed.
Best regards,
On 1/1/2013 10:03 PM, Robert Brown wrote:
It would be if the widget could accept certain keystrokes and use them as multiplers. For example "2m" should be converted to two million (2000000). 3b to 3 billion, 4k to 4000, etc etc.
These should of OFF by default. I imagine it could be a parameter like this:
|$('#someinput').autoNumeric({multipliers: {'k': 1000, 'm': 1000000, 'b': 1000000000}}); |
I had a look at the code and this seems tricky. There's lots there to stop extraneous chars from coming into the input at all, and then other code that handles pasted values, etc. I'd like to contribute but would appreciate from pointers on changes that would be required, etc.
Another, more general approach could be to allow callbacks after the value has changed. The receiver would accept the actual numeric value, plus suffixes (and prefixes I guess) and can then compute a new number to be returned to autoNumeric.
It also occurs to me that this callback approach would be useful for implementing min/max values that depend on other page elements, rather than initial widget setup. There are probably many other uses.
— Reply to this email directly or view it on GitHub https://github.com/funny-falcon/auto_numeric_js/issues/10.