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

Feature Request: denominators/multiplers #10

Open
rob99 opened this issue Jan 2, 2013 · 1 comment
Open

Feature Request: denominators/multiplers #10

rob99 opened this issue Jan 2, 2013 · 1 comment

Comments

@rob99
Copy link

rob99 commented Jan 2, 2013

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.

@BobKnothe
Copy link
Collaborator

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,

Bob
[email protected]

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
#10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants