Skip to content

Feature Request: denominators/multiplers #10

Description

@rob99

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions