Giter VIP home page Giter VIP logo

autonumeric / autonumeric Goto Github PK

View Code? Open in Web Editor NEW
1.8K 47.0 417.0 7.55 MB

AutoNumeric is a standalone library that provides live as-you-type formatting for international numbers and currencies.

Home Page: https://autonumeric.org

License: MIT License

JavaScript 92.35% HTML 7.60% Shell 0.05%
autonumeric javascript javascript-library maskedinput inputmask input-validation mask library numeric

autonumeric's Introduction

autonumeric.org

Latest Version Build Status Known Vulnerabilities Coverage Status GitHub Repo stars
Gitter chat Npm downloads per month jsDelivr downloads per month

What is AutoNumeric?

AutoNumeric is a standalone Javascript library that provides live as-you-type formatting for international numbers and currencies.

Highlights

AutoNumeric main features are:

  • Easy to use and configure
  • Very high configurability (more than 40 options available)
  • User experience oriented ; using autoNumeric just feels right and natural, specially with the function chaining feature
  • Supports most international numeric formats and currencies
    (If the one you use is not supported yet, open an issue and we'll add it as soon as possible!)
  • The mobile Android Chrome browser is partially supported

...and much more.

All in all, AutoNumeric supports most international numeric formats and currencies including those used in Europe, Asia, and North and South America.


Documentation

The documentation previously shown in that readme has now been moved to a specific web page where it's much more user-friendly; you can check it out on https://docs.autonumeric.org.

Tools

For checking the official AutoNumeric website, you can take a look at http://autonumeric.org. On this website you'll find additional tools for instance to generate your options configuration.


AutoNumeric versions

AutoNumeric provides 2 branches, master and next.

The very, very stable version is on the master branch (currently this is version 4.6.*).

The next branch contains all the new features and fixes, and is considered 'stable' too.

Do note that the next branch can see changes in the API (check the semver), but is always fully tested for regressions.
It's safe to use on production servers since it's always thoroughly tested and should not contain any bugs (that we know of).


Licence

AutoNumeric is an MIT-licensed open source project, and its authors are credited in AUTHORS.


Support

AutoNumeric is created using the JetBrains IDE, which kindly provide access to its tools to the developers.
If you feel AutoNumeric is useful to you, please consider supporting the project.

Contributors

Thanks to all the contributors over the years for making AutoNumeric a reality!

autonumeric's People

Contributors

alexandrebonneau avatar barvian avatar beastlike avatar bobknothe avatar carlos-ghan avatar chery-qualset-hcd-ca-gov avatar danielruf avatar jarinudom avatar kmoens avatar kossnocorp avatar lothairelaeuffer avatar lukasdrgon avatar marcdagatan avatar matthewthomsonnz avatar mcnetic avatar melloware avatar mseele avatar neunato avatar neyestrabelli avatar olsio avatar peterboccia avatar randoum avatar raylehnhoff avatar rhyek avatar sbusch avatar shrpne avatar svento avatar tetreum avatar wilmveel avatar zayter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autonumeric's Issues

Browsor backbutton causes reformatting already formatted numbers?

I am using ‘,’ as a decimal and ‘.’ as thousands separator. When hitting the back-button in the browser it looks like the already formatted numbers are formatted again. The thousands separator is seen as a decimal, meaning the numbers are corrupted. New loaded pages work fine.

E.g. value 100000 formatted as 100.000 will be 100 after hitting the back button.

Code:
jQuery(document).ready(function() {
$('input.sum').autoNumeric({aSep: '.', aDec: ',', mDec: '0'});
}

Tested in Chrome and IE 9.

Shouldnt jump thousands separator.

I think its weird that you jump the thousands separator.

Consider i have "1,000" and i want to change it to "1,200".
If the caret is after the 1 like this.

1|,000

As a user I think I need to move the caret left one space before I can delete the 0 and insert the 2.

So I click left but the caret is thousands separator (comma) is jumped and the caret ends up here.

1,0|00

I think you shouldn't jump the separator and after clicking left the caret should be after the separator. Like this.

1,|000

Looks like this is done around line 622.

PS. thanks for the library.

Need a third aPad setting - if not round, show decimals and leave trailing zero intact

I would need this kind of feature. I'm developing a calculation sheet with currency values. I would like to show round numbers without decimals for aesthetic / clarity reason, and otherwise show decimals with trailing zeros!

For what I understand, this isn't possible currently due to the settings provided (without tinkerking with the source) - am I correct?

Clone problem

init work when i first start autoNumeric on selector

When i create clone, clone element will not have autoNumeric initialized.
So i try and run autoNumeric again on same selector:
running autoNumeric 'init' will display error: use update...
running autoNumeric 'update' will display error: not initialized...

my guess is:
This happen because some elements of same selector have autoNumeric initialized and some do not. Is there a way to detect if element have autoNumeric initialized?

Number Error when aDec is ","

With the following autoNumeric options:

aDec: ",",
aSep: " ",   //space
dGroup: 3,
aPad: false,
mDec: null,
vMin: '0',
vMax: '999999999.999999'

the numbers are formatted incorrectly.
Ex: the number 0.79 turns to 79 000 000, whereas the required result is 0,79.

This problem was not there in the 1.8.5 version.

If aDec is changed to

aDec: "."

then it works fine.

Prevent special chars in all browsers

Currently, not all browsers prevent the input of special chars.
E.g. in Firefox it seems to be OK, but in Chrome and IE you can enter @ and other chars with ALT_GR + 1-0/Q/...

autoNumeric('get') does not return Numeric as comment states

Hey there love this plugin. Just upgraded to the latest 1.9.12 from 1.8.1. One thing I noticed is that autoNumeric('get') now returns a string value, instead of a numeric. I believe it is because of the use of .val(). Many of my unit tests are now failing because I was expecting it to return a numeric value but now it's a string. I will probably need to add something which does a parseInt and/or parseFloat. Would it be possible to add this into the plugin? or maybe a 'getNumeric' method?

Dealing properly with notable lag on initilization (with AJAX forms)

My webapp realies heavily on autoNumeric. It's a calculus sheet for certain kind of financial analysis. Done in AJAX fashion. At most there are total 103 autoNumeric inputs in a view!

I'm experiencing a notable lag while enabling/disabling some inputs by user interaction. I might have already clicked the input before it's properly initialized. Then when I hit the enter, the form gets submitted which is a no-no.

If you are interested to try this live send me an email, this might be an interesting use case for you although currently only in a foreign language.

UPDATE: I fixed the lag problem quickly by moving the action for enabling input to happen after autoNum init on the same chain. It was interesting though that as it took some time to initialize, if I clicked the input before that the autoNum wasn't then initialized anymore.

How to include decimals in the formatting

I already have the two decimal numbers, which I want to include into the formatted number. Example:

I have this number: 12534951
By default, autoNumeric does this: 12,534,951.00
I want to do this: 125,349.51

I have read through all the documentation and coudn't find any solution for my case.

plugin ignore settings.

I'm doing this:

$('#someID1').val("1.456");
$('#someID1').autoNumeric('init', {aSep: '.', aDec: ',', vMax: 99999.999});

the result is: 1,456, this value is wrong it' should be 1.456 because the group separator is '.' and decimal separator is ','

$('#someID2').val("1.456");
$('#someID2').autoNumeric('init', {aSep: ',', aDec: '.', vMax: 99999.999});

the result is: 1.456, this value is correct because the decimal separator is '.'

$('#someID1').val("1456");
$('#someID1').autoNumeric('init', {aSep: '.', aDec: ',', vMax: 99999.999});
the result is: 1.456,000, this value is correct

I've looked to the code and you are in lots of places ignoring the settings and just assume that group separator is ',' and decimal separator is '.' and this is wrong.

Is it possible to fix this in the following days?

Leading Zeroes Truncated with lZero:"keep"

When loading a page with an input that is already populated with a value that contains leading zeroes (for example, 000123456), autonumeric will strip the leading zeroes even if autonumeric is initialized with lZero:"keep". These zeroes are being stripped in the checkValue() method by the replace regex in the return statement.

Not Working for "tel" Input Type

I just upgraded from version 1.7.1 to 1.9.12. The autoNumeric plugin just stopped working for all "tel" type inputs. I believe this has to do with the several checks for input type such as:

if ($this.is('input[type=text], input[type=hidden], input:not([type])'))

Possible feature request: Minimum and maximum decimal places

I am working on a project where I need to enable the user to enter a price. The price field should always have at least 2 decimal places, but could contain many more (if dealing with extra-specific and extra-precise prices). The field should always be padded with 2 decimal places, but not more.

The idea is that the user can, if needed, enter more than 2 decimal places, but if they do not, then only 2 decimal places are show.

Is it somehow possible already or if not, perhaps this could be considered as a possible future feature?

getString fails when there is just one "autonumeric field" and that is empty

hi,
first : thanks for autonumeric, is great!
and second please see http://jsfiddle.net/aicl/6MXd8/11/

(tested with autonumeric 1.8.6 y jquery 1.9.1) ( it seems to work with autonumeric 1.8.3)

or try:

html:

Select an option ... Option 1 Save

js:

$("#cyt-input-5").autoNumeric();
$("#cyt-button-6").on("click", function(e){
e.preventDefault();
var s = $("#cyt-form-2").autoNumeric("getString");
alert (s);
})
/*

  1. "autonumeric field" = empty
  2. Click Save : it does not work !
    */

"Sometimes" Dollar sign get stripped out

I specified one of form element to have specific autoNumeric Format but when it goes over 1000 pretty often it dollar sign get strip out. Sometimes it works.
Here are the way I specified to turn on the autoNumeric and I do this when switching between edit Mode and readOnly mode.

$j('#form .hasNoChild .budget-value-column input').autoNumeric('init', {aSign: "$", vMax: 9999999.99, wEmpty: 'zero', mDec: 2 })

Dollar sign is always displayed

How can I make it so that when I have empty value I don't show dollar sign?
currently if it's on the td it shows dollar sign without any value for empty value

vMax with 15 digit or more not working properly

Hi, i am trying to setup autoNumeric for decimal input with 17 digit and 2 decimal place, but the autoNumeric give wrong output when the vMax is set more than or equals to 15 digit.

Here look at my example => http://jsfiddle.net/Bbrc3/8/

Is there something wrong with my code or is it related to the javascript limitation that you mention in issue 38?

Feature Request: Additional Suffix

I've got a need to put a suffix and a currency prefix, e.g.: "$10.00 (USD)" or "$10.00 gross"

If you're interested in implementing this, I've actually made the necessary modifications to my copy of autoNumeric and would be happy to send them to you. I added a property called aSuffix which (if set) is added to the end (after the currency if that has been set to suffix mode).

I could branch and add a pull request if you'd prefer but I figured this was easier for now.

Large Number display error in version 1.8.9

If the autoNumeric options set to the following:

{
   aDec: ".",
   aSep: ",", 
   dGroup: 3,
   mDec: 2,
   vMax: "999999999999999.999999",  //15 digits before the dot and 6 after
   vMin: "0"
}

and in the input field if we type characters with 14 or 15 digits before the dot and two after (as restricted by the options), the autoNumeric('get') return incorrect values in the last decimal digit.

Example:

  • Input Typed: 123,456,789,123,456.24 and autoNumeric('get') returns: 123456789123456.23 //last digit showing 3 instead of 4
  • Input Typed: 456,789,123,456,789.58 and autoNumeric('get') returns: 456789123456789.56 //last digit showing 6 instead of 8
  • Input Typed: 999,999,999,999,999.99 and autoNumeric('get') returns: 1000000000000000 //the entire amount is rounded up by 0.01

This does not happen in older version 1.8.5

$.fn.autoNumeric.Format missing?

First off, thanks for a great and useful library. I recently updated a project that was running 1.7.4-B and my code is blowing up when I'm using the autoNumeric function outside a selector

$.fn.autoNumeric.Format

I had a couple places where I was using the function to format items within my JS, not within the dom. Is that feature somewhere else? Or was it removed with the big change on 1.8?

Thanks!

How to format without decimal?

Hallo All..

I want to ask how to format number without decimal?

example :

1,000.00 to be 1,000

thank you for your hands...

reverse behavior in Kindle,Samsung Galaxy Tab

Hi
We are facing the issue in below devises.
Kindle Fire HD 9.8 and Samsung Galaxy Tab 10.1
In the field for Income, you cannot enter numbers correctly. You have to enter them in reverse.

Also, using the arrow keys do not work. neither does the Backspace key.

Thanks
Prasad.

autoNumeric + jquery 1.9.1: troubles !

hi, thanks for autoNumeric : is great!
I'm trying to use it with jquery 1.9.1 but some methdos ( getString, get ,set) throw this exception:
Cannot set property 'oEvent' of null

autoNumeric change value when field was disabled

Browser: Chrome (have not test in other browser yet)
Step to re-produce issue:

  1. input in the field some value
  2. don't leave the field, hit enter to trigger form submit event
  3. form submit handler disables the field in the form (note that the field is still focus)
  4. hit number key, and the value of that field is changed.

Release 1.9.17 version number was not updated

Just updated to 1.9.17 to resolve the "Fixed leading zero on page load when option lZero is set to 'keep'." and the version of autoNumeric.js for the 1.9.17 is still set to 1.9.16, just a heads up! Thank you.

Formatting error on init

Value is changed on init according to default options instead of the supplied options.
options {
aSep: '.',
aDec: ',',
mDec: 0,
vMax: '100000000'
};

input1.value = "339.361"
expected on init: "339.361"
actual: "339"

input2.value = "339,361"
expected on init: "339"
actual: "339,361"

See example on
http://jsfiddle.net/SHN65/
(autoNumeric-1.9.8 included)

AngularJS default value will not been formatted

I have an angular app and in the html I have an input field with ng-model="myViewModel.input.value".

In my controller there is:
$scope.myViewModel.input.value = 30000;

When I reload the page, I only see the value 30000 unformatted, when I change the focus from the input field to whereever, then all is ok. Tested with ng-model and value="{{myViewModel.input.value}}".

vMin and vMax optional parameters

According to documentation: To avoid many of these scenarios I recommend that you set vMin or vMax to "0" and validate later.

But when i set vMin and vMax to '0' only 0 is allowed to enter.

vMin and vMax should have the option to disable validation (by setting to null, 0, undefined ...

I would like to enter unlimited length of integers and validate on server using BigDecimal or BigInteger. Now this is not possible.

Japanese char and minus sign

I have this situation where i run the same page on a PC and on an iPad.

On the PC works great but on the iPad it shows weird values like japanese chars and some values do not even show, only thing that apears is a minus sign.
(the fields have width to show the values, already tried to put a very heigh width value but the output is the same)

here is the video:
http://--------------------------------

no errors on the console, all 3 columns use autonumeric.

Thanks in advance

Tag list and CDN

Super nice plugin - thanks :)

Two how-abouts:

  1. adding a few more (HTML5) elements - especially is a clear miss
  2. adding autoNumeric to cdnjs.com

Best,
Jakob E

number field not supported

Hey, is there any reason why the number field is not supported for this plugin, for example if I want to force numerical keyboard on android I want to have a type="number" field instead of a normal text field?

Multiple Form Behavior Unexpected

When using autoNumeric with an html page that has multiple forms with each having a currency field no matter what form is posted all currency field values are included in the post.

Not a bug per se but could create issues on the back end if post fields are present when they aren't expected. Sometimes code is written to check for the existence of a specific POST field.

The expected behavior is that only the fields inside the submitted form are included in the POST. However, autoNumeric includes all numeric fields regardless of the form submitted.

-- Christopher Mullins

Can`t clear field with entered some value and set vMin and vMax

Hi.

I faced with problem, when i setup autoNumeric with options vMin =0 and vMax=100, then enter value 12. Then try to remove 2 and the 1 - i could not make textbox empty. Is it possible to have opportunity to cleanup field without losing validation when user enter some value?

Opera mobile issue

Hi

Is there any chance to get autoNumeric to work with Opera mobile? I have tried on Android 2.3.3 and in Opera mobile emulator, and there seems to be a problem with preventing Opera's input. Each number I enter is displayed twice, invalid characters only get filtered on every third keypress, repeated keypressing removes previous characters.

Set function with aDec ","

Hi, I am not sure if this is an issue, but I am using the decimal place as comma, when I load some html page with a value like 4500,55, the autonumeric is not showing the value like 4.500,55.

I did some researchs inside the code, and to fix this I added the line below inside the Set function:

value = fixNumber(value, settings.aDec, settings.aNeg);

right after this line:
var $this = autoGet($(this)), settings = $this.data('autoNumeric'), value = valueIn.toString();

Is really missing that line?

Thanks and sorry about my English!
Marcelo

Leading zero when input value is currency

After moving from 1.7.5 to 1.9.1 I had a problem where some of my currency input values were having leading zeroes when they loaded. I fixed the problem by modifying line 381 in the autoRound method, but I'm not sure if there is a case where this will not be the best solution. I changed line 381 from

    if (!iv.match(/^\d/))

to

    if (iv.charAt(0) === '.')

I've created a fiddle that demonstrates the problem I'm having: http://jsfiddle.net/94zWF/2/

Thanks,
Chris

Bug when init autoNumeric to span

Hi All,

I found a bug using the follow line:

element.autoNumeric('init', {aSep: '.', aDec: ','});

In the first set (when runOnce is false) give me wrong result. For example to 123.45 after call that line, I give 12.345,00

Thanks

Format back to numeric value on POST

It would be nice if one doesn't have to re-format the posted value after POST to save a valid numeric value. Currently we have to strip out the added currency symbol. We also need to adjust the number (delocalize).

E.g: User input 1.234,56 € is posted exactly as this string.

We need it in 12345.56 (php internal numeric value) for storing again. Or at least in the local format 12.345,56 (which we can than unlocalize on save).

I just assumed this jquery plugin only takes care of a proper input format in regards of display. But unfortunately it also modifies the numeric value accordingly to a non numeric string.

Other similar plugins or HTML5 do that (formatting is only for display to the user).

Validation issue

Hi,

I've been using the autoNumeric plugin for quite a while now, started with version 1.7x and just updated to version 1.9x a couple of days back.

I'm having an issue when the value of the number field is set programatically using .val(), as opposed to a user entering the value.

What happens is that even though i have defined a vMax on the field (say 100), if i set the value to something greater (say elem.val(201)), the control is accepting it. Say I dont do anything and try to retrieve the value again from the field, i get back 201. Which is invalid.

Of course, if I focusin and then focusout from the element, the value is cleared as expected, because it is invalid. But it would be good if we could have the above scenario work as well.

I've created a fiddle for this. Can you please have a look at this? Thanks !

http://jsfiddle.net/NwCUt/3/

Allow select all from keyboard

When autonumeric is applied to a text field, the CMD + A keyboard combo brings the cursor at the beginning of the input rather than simply allowing to select the full value.

It would be rad to make sure the plugin does not override the expected CMD + A behaviour.

I would imagine this is an issue on windows as well with CTRL + A but I have no machine to test this on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.