UNPKG

@zeedhi/autonumeric

Version:

autoNumeric is a standalone Javascript library that provides live *as-you-type* formatting for international numbers and currencies. It supports most international numeric formats and currencies including those used in Europe, Asia, and North and South Am

591 lines (499 loc) 109 kB
## Changelog for autoNumeric ### 4.5.10 + Fixes #656 Input value will undo on focusout when using only Ctrl+Backspace ### 4.5.9 + Fixes #647 Caret position is incorrectly set when the `currencySymbol` in prefix position contains the first value entered *(ie. a numeric value)* ### 4.5.8 + Fixes #652 On initialization, `allowDecimalPadding` option `'floats'` does not hide the decimal zeroes if set in the html attribute ### 4.5.7 + Fixes #621 The `autoNumeric:formatted` event should be triggered when the input field is cleared while continuously pressing the `Backspace` or `Delete` keys *(for real this time, see `v4.5.2`)* ### 4.5.6 + Fix #602 Numpad decimal separator does not work on IE11 with a keyboard whose numpad decimal key outputs a comma + Adds a reference for the Angular 4+ implementation `ng-angular` component in the README ### 4.5.5 + Update the dev dependencies, fix the unit and end-to-end tests + Update the Babel version and fix the related configuration files + Update the Karma version and fix the related configuration files + Update the Webdriver.io version and fix the related configuration files + Update the Webpack version and fix the related configuration files ### 4.5.4 + Fixes #626 Missing the `\u0092` digit group separator ### 4.5.3 + Fixes #622 `freezeOptions()` can create issues in some browsers ### 4.5.2 + Fixes #621 The `autoNumeric:formatted` event should be triggered when the input field is cleared while continuously pressing the `Backspace` or `Delete`keys ### 4.5.1 + Fixes #611 The html `readonly` attribute is ignored on initial load + Fix how readonly and disabled inputs should not process keyboard events + Fix the formula mode so that the custom decimal character set with `decimalCharacter` is used instead of the default `'.'` character when writing float numbers ### 4.5.0 + Closes #542 Allow basic calculations when entering expressions like `=12*78` + Introduces the *formula mode* which allows a user to enter a math expression in the element using the `=` key, then evaluate it with the `Enter` one + Adds the `formulaMode` option, set to `false` by default, that controls if the *formula mode* is enabled + Adds the `Lexer`, `Parser`, `Evaluator`, `ASTNode` and `Token` classes for managing math expressions + Fixes #612 Dist files contain eval + The webpack `devtool` option for the `development` configuration has been changed from `cheap-module-eval-source-map` to `cheap-source-map`; This removes any `eval()` from the generated `dist/autoNumeric.js` file, and makes the source maps works in all cases in the browsers + Merge the changes from `4.4.1` while making sure there is no regression with #609; this adds the `browser` field alongside the `main` one in `package.json` + Note: The `browser` option points to the minified library `dist/autoNumeric.min.js` + Update the `index.html` test file to use the un-minified `development` library `dist/autoNumeric.js` This allows to *temporarily* use forbidden functions like `console` or wrong formatting while debugging, using `yarn build:dev` + Fixes a call to `_reformatAltHovered()` even when the `unformatOnHover` option was set to `false` ### 4.4.3 + Fixes #598 The `unformatOnHover` config value isn't used when set to `false` ### 4.4.2 + Fixes #609 Uncaught Error: Cannot find module 'autonumeric' on v4.4.1 + Reverts the changes from `4.4.1` : "Modify the `package.json` configuration `main` field to `browser`" ### 4.4.1 + Modify the `package.json` configuration `main` field to `browser` + This is useful per npm's documentation when the module is using browser-specific features like the `window` object ### 4.4.0 + Closes #476 Add a feature where `emptyInputBehavior` could be set to the minimum or maximum value + `emptyInputBehavior` now accepts either a number (or a string representing a number), or the `'min'` or `'max'` option + Fix the `emptyInputBehavior` validation test when checking the value limits + Fixes #579 Allow `emptyInputBehavior` to be set to min, max, or a number ### 4.3.7 + Fixes #594 Currency at wrong position for empty fields with euro/french preset after typing minus sign + Fixes #565 Entering a single minus character in a `negativeBracketsTypeOnBlur` input invert the currency sign and that minus sign ### 4.3.6 + Fixes #219 'Bug on form reset' that was re-opened + AutoNumeric now listens to the `reset` event on the parent form, and react accordingly if detected ### 4.3.5 + Really fixes issue #596 this time ### 4.3.4 + Fixes #596 Change event not firing depending on cursor movement ### 4.3.3 + Fixes #593 Pasting a negative value over a negative value that as a currency symbol and its numbers selected throws an error + Refactor the `_onPaste()` handler by removing duplicated parts + Fix the initialization call `new AutoNumeric()` where using as arguments a `string` (element selector), a `number` (initial value) and an `array` (array of options), in that particular order, would not be recognized ### 4.3.2 + Fixes #589 The `percentageUS*` predefined options do not have the `rawValueDivisor` option set ### 4.3.1 + Modify the `tenTrillions` and `oneBillion` limits to be exact + Remove the `maximumValue` and `minimumValue` `tenTrillionsNoDecimals` option, and update `tenTrillions` so that it equals ten trillions + The `tenTrillions` sub-option is now equal to `'10000000000000'`, and the `oneBillion` sub-option is now equal to `'1000000000'` + This change was long overdue since we modified in `v4.0.0-beta.22` how the number of decimal places was defined by the user using the `decimalPlaces` options instead of adding a specific number of decimal to the min/max values. ### 4.3.0 + Fixes #559 Allow AutoNumeric to accept the decimal character input even when there is already one in the element + Add the new `alwaysAllowDecimalCharacter` option set to `false` by default + Fixes AutoNumeric so that elements now correctly accepts entering a decimal char on the far left of a negative number ### 4.2.15 + Fixes #585 Internet Explorer 11 throws when freezing the options ### 4.2.14 + Fixes #526 Memory / speed improvement in options + Fixes #583 AutoNumeric `v4.2.13` forces the contenteditable attribute to `true` when set on the html source + Fixes #584 Event listeners are not set/reset on option updates ### 4.2.13 + Fixes #580 Allow non-input tags with the `readOnly` option to set the `contenteditable` attribute to `false` + Fix the `readonly` and `contenteditable` attributes so that they can be updated to read/write mode + Modify `_setReadOnly()` so that it *always* sets the element to read-only mode + Create a new `_setReadWrite()` function that sets the element to read-write mode + Create a new `_setWritePermissions()` function that sets the element read only/write mode according to the `readOnly` setting + Fix the urls to autonumeric.org in the readme ### 4.2.12 + Fixes #574 The fractional part is converted to an integer if the part on the cursor left-hand side is equal to 0 ### 4.2.11 + Fixes #570 The minified version of AutoNumeric does not expose some of its static functions (ie. `AutoNumeric.getNumber()`) + Removing the standard `Function.name` feature fixes the bug in IE now. In the near future IE users will need to require a polyfill for this. + Reduce the size of the generated library by tuning the UglifyJs options + Fix the end-to-end tests so that they are run against AutoNumeric's minified version ### 4.2.10 + Fix various bugs regarding the incorrect static and instantiated function calls + Fix the polyfill so that `Array.from()` is correctly 'polyfilled' even if the `CustomEvent` object already exists + Fix the `CustomEvent` polyfill + Merges PR #572 Use `AutoNumericHelper.contains()` instead of `String.includes()` for the time being + Update the dev dependencies + Update the babel preset from `latest` to `env` ### 4.2.9 + Fixes #568 Using brackets for negative numbers in AutoNumeric.format returns "undefined" ### 4.2.8 + Fixes #566 Add the Turkish predefined currency ### 4.2.7 + Fixes #521 The `input` event is not fired on `paste` if the element is empty or is completely selected beforehand + Fixes #563 The `import AutoNumeric from 'AutoNumeric'` line in the readme does not work on case sensitive OS (like Linux) ### 4.2.6 + Fixes #561 Webpack bundles the already compiled library when imported in another project ### 4.2.5 + Fix issue #550 The `change` event is sent twice on change + Fix the bug when an input with the `negativeBracketsTypeOnBlur` options was focused then blurred, it would dispatch a `change` event. ### 4.2.4 + Fix issue #558 Switch the webpack 4 ### 4.2.3 + Fix issue #556 Modify the `update()` function so that it can accept an array of options ### 4.2.2 + Fix issue #555 The `update()` function does not accept predefined option names (ie. `'euro'`) ### 4.2.1 + Fix issue #553 Missing support for very small or very big numbers displayed by Javascript as scientific numbers + This adds support for using scientific notation for setting the input value (ie. `aNInput.set('6.1349392e-13');`, `<input value="7342.561e40">`) ### 4.2.0 + Fix issue #535 Prevent entering any decimal character when only positive numbers are accepted + Change how the decimal character can be entered: + Before, the comma `','` and dot `'.'` where always accepted + Now, only the characters defined in `decimalCharacter` and `decimalCharacterAlternative` are accepted ### 4.1.3 + Fix the `.travis.yml` file so that the `dist` file are built on the CI server ### 4.1.2 + Fix the `.npmignore` file so that the npm autonumeric package can be installed ### 4.1.1 + Fix issue #554 Automatize the build and publishing process of releases with Travis CI + Remove the generated files from the git repository + Instead of polluting the repo with the `dist/*` files that can be generated using `yarn build`, those files are now generated and published to npm automatically when tagging a commit. ### 4.1.0 + Release `v4.1.0` The highlights of this version are: + New features + AutoNumeric static functions can now be used in web workers (#494) + Add the new `valuesToStrings` option to allow displaying a pre-defined string depending on the `rawValue` (#450) + Allow the positive & negative signs to be specified via the two options `positiveSignCharacter` and `negativeSignCharacter` (#478) + Add more details to the `'autoNumeric:formatted'` event payload (#485) + Add a new event hook `autoNumeric:rawValueModified` that will be sent only when the `rawValue` is modified (#488) + Add a new custom AutoNumeric event `'autoNumeric:initialized'` sent as soon as an AutoNumeric element is initialized + Add the static `set` and `get*` functions that will allow setting the given DOM element on getting its value without having a reference to its AutoNumeric object (#515) + Add support for watching external changes when setting the input `value` directly with Javascript without using the `set()` method (Note: watching the external changes from `textContent` is not yet supported) (#513) + Add the new option `watchExternalChanges` (set to `false` by default) that defines if the AutoNumeric object should watch and react to external changes (not made via `.set()`) + Add the new option `wheelOn` that defines when we should be listening to the `wheel` event, either on 'hover' or on 'focus' (#456) + Changes + Change the `modifyValueOnWheel` default behaviour to act only when the element is focused. If you want to be able to use the mouse wheel on a non-focused AutoNumeric element, you'll now need to press the `Shift` key while doing so. You can change that behavior back like it was before by setting the new option `wheelOn` to `hover` (#456) + Allow changing the `bubble` and `cancelable` attributes of events sent by AutoNumeric. This adds two new options `eventBubbles` and `eventIsCancelable` that defaults to `true` to manage those event attributes (#524) + Modify the static `getAutoNumericElement()`, `test()` and `isManagedByAutoNumeric()` functions so that they accept either a DOM element or a selector string (#514) + When the `rawValue` is allowed to be `null` and is effectively `null`, the min/max limits are now ignored + Form serialization now outputs the empty string `''` on empty inputs, instead of `0` or `0.00` (#512) + Improvements + Switch to Webpack 3.* for leaner bundle creations (#438) + Migration to eslint 4.* for a cleaner codebase (#475) + The `decimalCharacterAlternative` now correctly ignores the 'comma' or 'dot' when set to `none` (#432) + Unit test now use the `mocha` profile as default instead of `progress` + Fixes + Coverage information is back (#490) + Workaround a geckodriver bug when trying to input an hyphen (#480) + Fix lots of pasting issues (#481, #482, #483, #484, #505, #510, #547) + Create workarounds (*hacks* really) for various IE-related bugs (#495, #516, #518) + `AutoNumeric.multiple()` now correctly add only one event listener to the parent form, if any (#457) + The `input` event is not fired on mouse wheel (#525) + Prevent using the `wheel` event on `disabled` input elements + The value of a read-only field can be changed with a scroll input (#541) + Cut text reappears when leaving the field (#527) + Input is duplicated and reversed on devices with Android < 7.0 using Android Chrome (#522) + Formatted numbers on Android Chrome do not get deleted on blur anymore ...and [more](https://github.com/autoNumeric/autoNumeric/projects/2). ### 4.1.0-beta.28 + Fix issue #477 Modifying an input by selecting all its content and entering `0` drop the current selection, if 0 is out of the limit boundaries ### 4.1.0-beta.27 + Fix issue #432 The `decimalCharacterAlternative` option does not ignore the comma when it's set to `none` ### 4.1.0-beta.26 + Fix issue #522 Input is duplicated and reversed on devices with Android < 7.0 + Remove the `input` event listener + Refactor parts of the `_stripAllNonNumberCharacters` and `_convertToNumericString()` functions by creating a `_normalizeCurrencySuffixAndNegativeSignCharacters()` function + Rename `_stripAllNonNumberCharacters()` to `_stripAllNonNumberCharactersExceptCustomDecimalChar()` + Create a `_stripAllNonNumberCharacters()` function that also normalize the decimal character + Remove the obsolete `skipFirstAutoStrip` and `skipLastAutoStrip` regex + Prevent the conversion of the `decimalCharacterAlternative` into the `decimalCharacter` when stripping the value + Simplify `_addBrackets()` and `_setBrackets()` + Simplify the `_removeBrackets()` calls + Fix `_convertToNumericString()` so that it normalize the positive sign and remove the brackets if any + Fix the bug where the formatted numbers on Android Chrome gets deleted on blur + Simplify the generated cached regex + Refactor `_processCharacterDeletionIfTrailingNegativeSign()` so `contains()` is called only once ### 4.1.0-beta.25 + Add a new custom AutoNumeric event `'autoNumeric:initialized'` sent as soon as an AutoNumeric element is initialized ### 4.1.0-beta.24 + Fix issue #527 Cut text reappears when leaving the field ### 4.1.0-beta.23 + Fix issue #547 Newer version of Firefox breaks pasting in `contenteditable` elements + Fix issue #510 Pasting values in a `disabled` element should not be possible + Also prevent using the `wheel` event on `disabled` input elements. ### 4.1.0-beta.22 + Fix issue #525 The `input` event is not fired on mouse wheel ### 4.1.0-beta.21 + Fix issue #541 The value of a read-only field can be changed with a scroll input ### 4.1.0-beta.20 + Fix issue #489 `valuesToStrings` is ignored when using the static `format()` and `unformat()` functions ### 4.1.0-beta.19 + Add an option `watchExternalChanges` to react to external changes By default, an AutoNumeric element only format the value set with the `.set()` function. If you want the element to watch and format value set by third party script using the `aNElement.node().value = 42` notation, then you need to set the `watchExternalChanges` option to `true`. ### 4.1.0-beta.18 + Fix issue #524 Allow changing the `bubble` and `cancelable` attributes of events sent by AutoNumeric + Add two new options `eventBubbles` and `eventIsCancelable` that defaults to `true` to manage the event attributes. ### 4.1.0-beta.17 + Fix issue #457 Using `AutoNumeric.multiple()` generate many `submit` event listeners on the parent `form` + Fix the `drop` event handler removal that was omitted. + Add a global `aNFormHandlerMap` Map on the `window` object, that keep track of all `submit` event handler for each `<form>` element that has at least one AutoNumeric-managed element child. ### 4.1.0-beta.16 + Fix issue #456 Change the `modifyValueOnWheel` default behaviour to act only when the element is focused + Add a new `wheelOn` option that will define when the `wheel` event will increment/decrement the element value. By default the `wheel` event is only used when the element is focused (`wheelOn` is set to `'focus'`), but you can also use the `'hover'` option if you want to keep the previous behavior. Note: There is a small caveat since the `Shift + mouse wheel event` is reserved by browsers for horizontal scrolling, using the `Shift` key and the `wheelOn` option set to `'hover'` will only scroll the page while the mouse *is hovered* over the AutoNumeric-managed element. Once it's out of the way, the page won't scroll since you'll be holding the `Shift` key. You'll then be able to scroll the page normally without having to hold that `Shift` key. ### 4.1.0-beta.15 + Fix issue #513 Setting the input `value` directly with Javascript without using the `set()` method is not supported From now on, if an external change is detected when a script modify the input `value` attribute directly, AutoNumeric tries to format the new value. Note: watching the external changes to `textContent` is not supported yet. + Fix `_onFocusInAndMouseEnter()` where `setElementValue()` was called multiple times in a row + Fix the `AutoNumeric.events.formatted` event so that only one is sent for each user action + Change: The `AutoNumeric.events.formatted` event is not sent anymore when wiping an AutoNumeric object ### 4.1.0-beta.14 + Fix issue #516 'Del' key does not work in IE browser + Fix issue #509 `allowDecimalPadding` set to `'floats'` when `decimalPlaces` is different from `0` output a warning ### 4.1.0-beta.13 + Fix issue #518 'Drag-and-Drop' operation does not work in IE11 ### 4.1.0-beta.12 + Fix issue #514 Modify the static `getAutoNumericElement()`, `test()` and `isManagedByAutoNumeric()` functions so that they accept either a DOM element or a selector string + Fix issue #515 Add the static `set` and `get*` functions ### 4.1.0-beta.11 + Fix issue #455 Uncaught Error: `_initialCaretPosition()` should never be called when the `caretPositionOnFocus` option is `null` + Fix issue #512 AutoNumeric serialized data return `0` instead of an empty value on empty inputs This fix changes how form serialization is done, by outputting the empty string on empty inputs, instead of `0` or `0.00`. ### 4.1.0-beta.10 + Fix issue #502 The end-to-end tests fails on Chrome 61 + Fix issue #505 Pasting values in a `readOnly` element should not be possible ### 4.1.0-beta.9 + Fix issue #498 The `twoScaled` choice for the `digitalGroupSpacing` option cannot be validated + Convert all the end-to-end test `browser.execute()` calls so that hardcoded DOM ids are not used anymore ### 4.1.0-beta.8 + Fix issue #496 The upgrade guide to v4 references the `decimalPlacesOverride` option without indicating it's deprecated + Fix issue #479 Whitespace on the left hand side of the html `value` attribute adds a zero on the formatted value on page load ### 4.1.0-beta.7 + Fix issue #495 `AutoNumeric.multiple()` fail on IE11 on unknown `Array.from()` ### 4.1.0-beta.6 + Fix issue #494 Allow AutoNumeric to be imported in web workers in a webpack setup ### 4.1.0-beta.5 + Fix issue #493 When `formatOnPageLoad` option is set to `false`, neither the `rawValue` nor the element value are set ### 4.1.0-beta.4 + Fix issue #438 Upgrade Webpack to 3.* + Fix issue #490 Fix the generated coverage information + Modify the unit test reporter to use 'mocha' instead of 'progress', in order to get more insightful reports. + Move the configuration files for the unit tests in the `test/unit` directory. + Update the dev dependencies (Babel, Babel-polyfill, Uglify, PhantomJS, Jasmine). ### 4.1.0-beta.3 + Fix issue #485 Add more details to the `'autoNumeric:formatted'` event payload + Fix issue #488 Add a new event hook `autoNumeric:rawValueModified` that will be sent only when the `rawValue` is modified ### 4.1.0-beta.2 + Fix issue #478 Allow the positive & negative signs to be specified via options + Fix issue #480 On Firefox, the end-to-end tests fails when trying to send the minus `'-'` character. + Also fix the selenium tests where entering the hyphen (`'-'`) character was not correctly accepted under Firefox. This was due to the fact that the wrong keyCode `173` is sent instead of `189` like in all the other browsers for that character. + Fix issue #481 When the caret is on the far right and the negative sign too, entering `'+'` or `'-'` does not toggle the positive state, and only move the caret from one character to the left. + Fix issue #482 Pasting a positive value while selecting the entire content of an element that has a negative value result in an error. + Update the 'Options' chapter in the documentation to add some details on a few options. + Simplify `_checkPaste()` so that it's not processed any more times if the element has already been formatted. + Fix the range check so that when the `rawValue` is allowed to be `null` and is effectively `null`, the min/max limits are ignored. + Modify how `this.formatted` is used so it tracks if the element value has been formatted already. If that's the case, prevent further format calculations. This is a start and `this.formatted` usage should be reviewed in depth. + Fix issue #484 Pasting an invalid string into either a selection or at the caret position modify the element value. + Fix issue #483 Pasting a content over an element that already has the same exact content resets its value to zero. ### 4.1.0-beta.1 + Fix issue #475 Migrate to eslint 4 + Fix issue #450 Add the `valuesToStrings` option to allow displaying a pre-defined string when the `rawValue` equal a specific value ### 4.0.3 + Fix issue #474 `AutoNumeric.format()` and `AutoNumeric.unformat()` do not accept named options ### 4.0.2 + Fix issue #473 Static `format()` and `unformat()` functions ignores the `rawValueDivisor` option + Fix `AutoNumeric.unformat()` that used the number of decimal places shown on focus instead of the one for the raw value. ### 4.0.1 + Fix issue #471 The static `format()` function does not keep the negative sign + Fix issue #472 The static `AutoNumeric.format()` function does not accept DOM element as its first parameter ### 4.0.0 + Release `v4.0.0` + The highlights of this new version are: - AutoNumeric is now fully converted to an ES6 module. - No more jQuery dependency. - `AutoNumeric` is now a class. You can access the class method directly from the AutoNumeric object (ie. `const aNElement = new AutoNumeric(input, {options})); aNElement.set(123).update({options2});`). - The number of decimal places is now explicitly set via the `decimalPlaces` option. - You can now specify a different number of decimal place to show when focused and unfocused, and for the internal `rawValue`. If you relied on the number of decimals in `minimumValue` or `maximumValue` to define how many decimal places should be shown on the formatted value, or kept as the precision in the `rawValue`, you now need to explicitly define how many decimal places your want, whatever number of decimal places `minimumValue` and `maximumValue` have. - You can now 'cancel' any edits made to the element by hitting the `Escape` key. If no changes are detected, hitting `Esc` will select the element value (according to the `selectNumberOnly` option). - Undo/Redo are now supported. - You can modify the value of the element by using the mouse wheel on it, if `modifyValueOnWheel` is set. The `wheelStep` option defines the step to use. - An AutoNumeric object can now initialize other DOM elements with `init(domElement)`, which will then use the same options. The AutoNumeric-managed elements that initialized each other share a common list, allowing the user to perform a single action on many elements at once (via the `.global.*` functions, ie. `aNElement.update({options})` to update the options of all the elements, or `aNElement.set(42)` to set the same value for each elements). The `.global.*` functions you can use are : `set()`, `setUnformatted()`, `get()`, `getNumericString()`, `getFormatted()`, `getNumber()`, `getLocalized()`, `reformat()`, `unformat()`, `unformatLocalized()`, `update()`, `isPristine()`, `clear()`, `remove()`, `wipe()`, `nuke()`, `has()`, `addObject()`, `removeObject()`, `empty()`, `elements()`, `getList()` and `size()`. Managing that shared list is possible via `attach()` and `detach()`. - The options can now be updated one by one using the handy functions `aNElement.options.<nameOfTheOption>({newOption})`, ie. `aNElement.options.currencySymbol('€')`. You can also reset the options to the default ones using `aNElement.options.reset()`. - Lots of new options (`rawValueDivisor`, `decimalPlaces`, `decimalPlacesRawValue`, `decimalPlacesShownOnBlur`, `serializeSpaces`, `noEventListeners`, `readOnly`, `selectOnFocus`, `caretPositionOnFocus`, etc.). - While the AutoNumeric objects provides many methods, you can also directly use the AutoNumeric class static functions without having to instantiate an object. Those methods are `version()`, `test()`, `validate()`, `areSettingsValid()`, `getDefaultConfig()`, `getPredefinedOptions()`, `format()`, `formatAndSet()`, `unformat`. `unformatAndSet()`, `localize()`, `localizeAndSet()`, `isManagedByAutoNumeric()` and `getAutoNumericElement()`. - Lots of new functions (`isPristine()`, `clear()`, `nuke()`, `formatOther()` and `unformatOther()` which allows to format/unformat a numeric string or another DOM element with the current object settings, `setValue()`, etc.). - The `get()` function has been deprecated, in favor of more explicit `get*` methods : `getNumericString()`, `getFormatted()`, `getNumber()` and `getLocalized()`. - By default, `new AutoNumeric('.myClass')` will only initialize *one* element. If you want to initialize multiple DOM elements in one go, you need to use the static `AutoNumeric.multiple()` function. It allows to initialize numerous AutoNumeric objects (on numerous DOM elements) in one call (and possibly pass multiple values that will be mapped to each DOM element). - Support for the Android Chrome mobile browser (v57) (this is a work in progress though, since it's quite hard to work around its limitations). - Functions can now be chained (ie. `aNElement.clear().set(22).formSubmitJsonNumericString().nuke()`). Modify how updating the settings works ; before, all modifications to the settings were directly accepted and stored, then we immediately tried to `set()` back the current value with those new settings. This could lead to an object state where the object value would be out of the minimum and maximum value range, ie. we would accept the range modification, then immediately throw an error since the current value would then be out of range. For instance, if `minimumValue` equal `0`, `maximumValue` equal `100` and the current element value equal `50`, trying to change the `minimumValue` to `75` will fail, and the `minimumValue` will be reverted back to`0`. The new behavior is leaner ; if the new settings do not pass the `validate()` method or the following `set()` call fails, then the settings are reverted to the previous valid ones. - The `rawValueDivisor` option allows to display a formatted value different than the raw value. For instance you can display percentages like `'1.23%'`, while keeping the `rawValue` `0.0123` 'unmultiplied', if `rawValueDivisor` is set to `100`. + And also: - The new `selectNumber()`, `selectInteger()` and `selectDecimal()` function to select the element content as needed. - The DOM-specific functions to manipulate it ; `node()` (returns the DOM element managed by AutoNumeric), `parent()`, `form()` (returns the parent <form> element, if any). - More than 20 functions to manages html forms ; how to retrieve info from them, or submit the info (formatted, unformatted, localized). - Predefined options so that the user do not have to configure AutoNumeric manually. Those options are `dotDecimalCharCommaSeparator`, `commaDecimalCharDotSeparator`, `integer`, `integerPos`, `integerNeg`, `float`, `floatPos`, `floatNeg`, `numeric`, `numericPos`, `numericNeg`, `euro`, `euroPos`, `euroNeg`, `euroSpace`, `euroSpacePos`, `euroSpaceNeg`, `percentageEU2dec`, `percentageEU2decPos`, `percentageEU2decNeg`, `percentageEU3dec`, `percentageEU3decPos`, `percentageEU3decNeg`, `dollar`, `dollarPos`, `dollarNeg`, `percentageUS2dec`, `percentageUS2decPos`, `percentageUS2decNeg`, `percentageUS3dec`, `percentageUS3decPos` and `percentageUS3decNeg`. - Some language options are now shipped directly and you can use the language name as a function to activate those settings (ie. `aNElement.french()`). - Better support for `contenteditable` elements so that AutoNumeric is not only limited to `<input>` elements. - AutoNumeric send the `'autoNumeric:formatted'` event whenever it formats the element content. - The raw unformatted value can always be accessible with the `rawValue` attribute (ie. `aNElement.rawValue`). - When pressing the `Alt` key, you can hover your mouse over the AutoNumeric-managed elements to see their raw value. - You can prevent the mouse wheel to increment/decrement an element value by pressing the `Shift` key while using the mouse wheel. - Default values for each options can be easily accessed with an IDE autocompletion when using `AutoNumeric.options.|`. - Support for drag and dropping numbers into AutoNumeric-managed elements. - The `styleRules` option allows to either change the style of the current element based on the `rawValue` value, or just call any custom callbacks whenever the `rawValue` changes. - Allow setting the `rawValue` to `null`, either by setting it directly (ie. `aNElement.set(null)`), or by emptying the element, if `emptyInputBehavior` is set to `'null'`. - All `get*()` method accepts a callback function. The callback is passed the result of the `get*` functions as its first argument, and the current AutoNumeric object as its second. - Allow initializing an AutoNumeric element with an array of options objects or pre-defined option names (ie. `'euroPos'`). - Add a static `AutoNumeric.mergeOptions()` function that accepts an array of option objects and / or pre-defined option names, and return a single option object where the latter element overwrite the settings from the previous ones. + *Lots* of bug fixes and code simplification (#387, #391, #393, #397, #399, #398, #244, #396, #395, #401, #403, #408, #320, #411, #412, #413, #417, #423, #415, #418, #409, #416, #414, #427, #248, #425, #264, #250, #404, #434, #440, #442, #447, #448, #449, #454, #453, #388, #461, #452). + Better test coverage, both for unit tests and end-to-end tests. + Rewrite the documentation (README.md) to make it more 'browsable'. + For a more detailed changelog, you can read the changes listed from `v3.0.0-beta.1` to `v3.0.0-beta.14` and from `v4.0.0-beta.1` to `v4.0.0-beta.23`. ### 4.0.0-beta.23 + Fix issue #453 Rename the `noSeparatorOnFocus` option to `showOnlyNumbersOnFocus` + Add the missing `options.historySize()` method that allows to update the `historySize` option + Move the raw value from `this.settings.rawValue` to `this.rawValue`. This prevent polluting the settings object. + Fix issue #388 autoNumeric does not work with Browserify + Fix issue #461 Fixed problem on Android Chrome browsers when a currency symbol is used + Fix issue #452 Add a new `rawValueDivisor` option to display a formatted value different than the raw value. This allows for instance to display percentages like `'1.23%'`, while keeping the `rawValue` `0.0123` 'unmultiplied', if `rawValueDivisor` is set to `100`. + Merge the `blur` event listeners into one. + Add the `this.isWheelEvent`, `this.isDropEvent` and `this.isEditing` attributes to track the `wheel` and `drop` events, as well as when the user is manually editing the element value. + Modify `_setRawValue()` to divide the `rawValue` if `rawValueDivisor` is set. + Fix the validation test for the `scaleDivisor` option where it did not check that it should not be equal to `0`. + Fix the validation test for the `allowDecimalPadding` when `decimalPlacesShownOnBlur` or `decimalPlacesShownOnFocus` is set. + Add a validation test for `divisorWhenUnfocused` so that it throws if it's set to `1`. + Modify the validation test so that setting `divisorWhenUnfocused` to `1` will throw. + Modify `_trimLeadingAndTrailingZeros()` so that it manages `null` values correctly (ie. it returns `null` instead of `'0'` if passed `null`). + Fix the error shown when blurring an input that accept a `null` value. + Modify the pre-defined options `percentage*` so that the `rawValueDivisor` is set to `100`. + Rename the `divisorWhenUnfocused` option value from `doNotActivateTheScalingOption` to `none`. + Fix `getNumericString()` so that it returns `null` when the `rawValue` is `null`. + Separate the `_calculateDecimalPlaces()` function into two `_calculateDecimalPlacesOnInit()` and `_calculateDecimalPlacesOnUpdate()`. + The callbacks found in the `settings` object are now run before modifying the `negativePositiveSignPlacement` option. + Modify how the settings are updated when the user pass the `decimalPlaces` option. Before, this was overriding any other `decimalPlaces*` options passed in the same object. Now, the `decimalPlaces` value is only used if the other `decimalPlaces*` options are not already set. Moreover, the `decimalPlacesRawValue` option is now overwritten by the other `decimalPlaces*` options defined in the same option object, if their values are higher. + Modify the behavior of the `wheelStep` 'progressive' mode so that values between ]-1;-1[ are treated specially, by allowing the wheel event to modify the decimal places. The precision used for the `step` depends on the number of decimal places used for the `rawValue`. Also, numbers between 1 and 9 (included) now use a step of `1`, instead of `10` like before. + Set the version of Webpack to `1.14.0`, instead of `latest`, in order to prevent potential incompatibility problems. ### 2.0.13 + Merge the fix from issue #440 Pasting does not work in IE11 from `next` to `master`. This fix the issue #465 "Unable to get property 'getData' of undefined or null reference" on paste in IE11 + Merge the fix from issue #449 `AutoNumeric.unformat()` only removes the first instance of `settings.digitGroupSeparator` from `next` to `master`. ### 4.0.0-beta.22 + Fix issue #454 Rewrite how the number of decimal places for the formatted and the raw values are set + If you relied on the number of decimals in `minimumValue` or `maximumValue` to define how many decimal places should be shown on the formatted value, or kept as the precision in the `rawValue`, you now need to explicitly define how many decimal places your want, whatever number of decimal places `minimumValue` and `maximumValue` have. + To do so, you now need to define at least the `decimalPlaces` option. + If you want, you can also separately define `decimalPlacesRawValue`, `decimalPlacesShownOnBlur` and `decimalPlacesShownOnFocus`. For more details, read on. + Rename `scaleDecimalPlaces` to `decimalPlacesShownOnBlur`. + Rename `scaleDivisor` to `divisorWhenUnfocused`. + Rename `scaleSymbol` to `symbolWhenUnfocused`. + Rename the `decimalPlacesShownOnBlur.doNotChangeDecimalPlaces` to `decimalPlacesShownOnBlur.useDefault` to be coherent with the other `decimalPlaces*` options. + Remove the `decimalPlacesOverride` option in favor of explicit `decimalPlaces`, `decimalPlacesShownOnBlur` and `decimalPlacesShownOnFocus` ones. + Add a warning message if the old `mDec` option is used (which was the equivalent of `decimalPlacesOverride`). + Add a `decimalPlacesRawValue` option that define the precision the user wants to keep (in the `rawValue`). + Remove the need for saving `decimalPlacesOverride` to temporary change it in `set()`. + Create 3 different rounding functions that replace the `_roundValue()` calls: `_roundFormattedValueShownOnFocus`, `_roundFormattedValueShownOnBlur` and `_roundRawValue`. This way we are more explicit in what the code is doing. + Modify `_setRawValue()` so that it only save the given raw value if it's different than the current one (keeping the history table clean). + Use template strings instead of concatenation in `_addGroupSeparators()`, `_roundValue()` and `_prepareValueForRounding()` to prevent possible wrong typecasts. + Fix the error shown when hovering an input whose value has been set to `null` (a `toString()` was attempted on the `null` value in the `_roundValue()` method). + Fix the incoherent variable name `inputValueHasADot` in `_roundValue()` to better reflect what data it holds, ie. `inputValueHasNoDot`. + Fix typos in the `set()` warning messages. + Add a warning message when try to set a value that results in `NaN`. + Simplify the '_onFocusInAndMouseEnter` and `_onFocusOutAndMouseLeave` event handlers. + Update the tests with the new changes. + Modify how decimal places are set. Before you needed to add that many decimals to the `minimumValue` or `maximumValue`, and that maximum number of decimal place was used everywhere (except if you also defined `decimalPlacesOverride`, `decimalPlacesShownOnFocus` or `scaleDecimalPlaces`). Now you need to explicitly define the number of decimal places using the `decimalPlaces` option. If only `decimalPlaces` is defined, then the other `decimalPlaces*` options `decimalPlacesRawValue`, `decimalPlacesShownOnBlur` and `decimalPlacesShownOnFocus` are calculated from it. This way, you can now define clearly how many decimal places needs to be shown when focused/unfocused, and as the raw value precision. Note: updating the `decimalPlaces` will overwrite any `decimalPlaces*` option previously set. + Remove the `_maximumVMinAndVMaxDecimalLength()` since we do not set the number of decimal places this way. + Remove the `_correctDecimalPlacesOverrideOption()` function since `decimalPlacesOverride` is not used anymore. + Add a `_calculateDecimalPlaces()` static method that calculate the `decimalPlaces*` option value based on `decimalPlaces` and the `decimalPlaces*` ones. + Modify how updating the settings works ; before, all modifications to the settings were directly accepted and stored, then we immediately tried to `set()` back the current value with those new settings. This could lead to an object state where the object value would be out of the minimum and maximum value range, ie. we would accept the range modification, then immediately throw an error since the current value would then be out of range. For instance, if `minimumValue` equal `0`, `maximumValue` equal `100` and the current element value equal `50`, trying to change the `minimumValue` to `75` will fail, and the `minimumValue` will be reverted back to`0`. The new behavior is leaner ; if the new settings do not pass the `validate()` method or the following `set()` call fails, then the settings are reverted to the previous valid ones. + In `_setValueParts()`, set the `rawValue` and the formatted element value separately, since they can have different decimal places. For instance we could imagine keeping 3 decimal places for the `rawValue`, while only 2 is shown. I then need to make sure we keep that third decimal place information into the `rawValue`, instead of trimming it like it was done before. ### 4.0.0-beta.21 + Set the read-only mode on the default settings, enumerations, events, options and pre-defined options objects. + Allow using a pre-defined option name directly when initializing an AutoNumeric element + Fix the initialization method to accepts arrays of options object/pre-defined options when using an initial value. + Fix an issue related to issue #447 when the focus out action produce an error when the input raw value is set to `null` + Fix a rare bug when `scaleSymbol` is a castable to a `Number`, and would be added to the formatted value, instead of concatenated. + Remove an unneeded temporary variable in `set()`. + Add more details in some JSDoc. + Fix `validate()` so that it throws an error early if `scaleDivisor` is wrongly set to `0`. + Fix `_trimLeadingAndTrailingZeros()` so that it correctly handles the `null` value. + Fix `_onFocusInAndMouseEnter()` so that the `decimalPlacesShownOnFocus` setting is correctly cast to a Number. + Fix `_onFocusOutAndMouseLeave()` so that the `null` value is correctly handle. Also fix the error message shown when the `rawValue` is not stored as a string. + Simplify a ternary condition into a simple `if` one. + Hardcode the `isFocused` state to `false` when calling `_addGroupSeparators()` in `_onFocusOutAndMouseLeave()` so that it does not rely on the order where `this.isFocused` is set back to `false`. ### 4.0.0-beta.20 + Allow initializing an AutoNumeric element with an array of options objects or pre-defined option names. The latter options in the array will overwrite the previous ones. The array can contains either option objects, or pre-defined option names as a string (ie. `'euroPos'`). Both the initialization methods `new AutoNumeric()` and `AutoNumeric.multiple()` support using arrays of options. + Add a static `AutoNumeric.mergeOptions()` function that accepts an array of option objects and / or pre-defined option names, and return a single option object where the latter element overwrite the settings from the previous ones. + Allow passing an array of options objects or pre-defined option names to the static `format` and `unformat` methods. The latter options in the array will overwrite the previous ones. The array can contains either option objects, or pre-defined option names as a string (ie. `'euroPos'`). ### 4.0.0-beta.19 + Fix issue #449 `AutoNumeric.unformat()` only removes the first instance of `settings.digitGroupSeparator` ### 4.0.0-beta.18 + Modify the `get*` methods to allow passing them a callback function. + The callback is then executed on the `get*` method result, or the `global.get*` method array of result. + The callback is passed the result of the `get*` functions as its first argument, and the current AutoNumeric object as its second. + Split the `_saveValueToPersistentStorage()` method in three : `_saveValueToPersistentStorage()` to save the raw value to persistent storage, `_getValueFromPersistentStorage()` to retrieve that data, and `_removeValueFromPersistentStorage()` to delete it. + From now on, the `_storageTest` is only done once, and the result is kept in `this.sessionStorageAvailable`, and the storage variable name is also generated once and kept in `this.rawValueStorageName`. + You can now modify the raw value storage name variable prefix by modifying the `this.storageNamePrefix` attribute. Currently it defaults to `'AUTO_'`; ### 4.0.0-beta.17 + Fix issue #447 Add a new `'null'` options to the `emptyInputBehavior` setting + Add the `this.defaultRawValue` variable that store the hard-coded default raw value used during the initialization and reset. + When using the option `{ emptyInputBehavior: AutoNumeric.options.emptyInputBehavior.null }`, the user can now explicitly set the AutoNumeric value to `null` (using `anElement.set(null)` for instance). Additionally, when this option is set, if the AutoNumeric element is emptied, then `rawValue` is set to `null`. Note: if the current raw value is equal to `null`, changing the `emptyInputBehavior` option to something different than `null` will update the rawValue to `''`. **Known limitation** : Initializing an AutoNumeric object with the `null` value is not allowed since using `null` for the initial value means that AutoNumeric needs to use the current html value instead of `null`. + Fix issue #448 When searching for the parent form element, the `tagName` can be undefined. + The `form()` method now accepts a `true` argument that will force it to discard the current parent form and search for a new one. + Enforce the use of `settings.showWarnings` for most calls to `AutoNumericHelper.warning()`, wherever possible. ### 4.0.0-beta.16 + Move the options, default options and predefined options objects each in its own file. Separating them from the AutoNumeric class makes that information easier to find, study and modify. + Modify the `update()` and `global.update()` function signatures so that they can accept multiple option objects, the latter overwriting the settings from the former. This allows to fine tune the format settings in one go, and is specially useful when using a predefined option as the 'configuration base', and changing it slightly (ie. `anElement.update( AutoNumeric.getPredefinedOptions().French, { digitGroupSeparator: AutoNumeric.options.digitGroupSeparator.noSeparator })`). + Fix the `'autoNumeric:formatted'` event not being correctly sent if the AutoNumeric element was formatted without a `keyup` event. The event is now correctly sent when the value is set to empty, or when using `unformat()`, `unformatLocalized()` and `wipe()`, as well as when the user uses the wheel event to change the element value, or the `alt + mouse hover` feature, or just hover the element that has a `negativeBracketsTypeOnBlur` option set, or on the initial format on load. + Fix the fact that `'autoNumeric:formatted'` was not sent when pasting valid values. + Gather the AutoNumeric event names in a single configuration variable `AutoNumeric.events`. + Modify the default percentage pre-defined option `wheelStep` to `0.01` so that the wheel step is more logical when manipulating a small number. + Fix issue #442 Setting `unformatOnSubmit` to `true` does not unformat the element on the form' `submit` event + Fix issue #440 Pasting does not work in IE11 ### 4.0.0-beta.15 + Add a new option `selectOnFocus` that allow the user to choose if the value should be selected when the element is focused. + Add a new option `caretPositionOnFocus` that allow the user to choose where should be positioned the caret when the element is focused. + Modify how the caret is treated on focus ; if the `selectOnFocus` option is `true` then the value is selected, otherwise the caret is set at the position defined by the `caretPositionOnFocus` option. + `caretPositionOnFocus` can be `'start'`, `'end'`, `'decimalLeft'` and `'decimalRight'`, and will change where the caret will be positioned when the element get the focus. It can also be `null` which means the caret position is not forced. + The caret position is calculated by the new `_initialCaretPosition()` function. + Modify `validate()` so that an empty object can be used for the options, since the default settings would then be merged and used. + Modify the `validate()` function signature so that it accepts a third argument, the raw options passed by the user, without them having been merged with the default settings. This is useful for checking conflicting options that could be overwritten by the defaults. + Rewrite the call to `validate()` from `areSettingsValid()` to make it more explicit. + Rewrite one test condition in `_onFocusInAndMouseEnter()` so that it's not reserved only for elements that have their `emptyInputBehavior` option set to `focus` anymore. + Add a `focusin` event handler via `_onFocusIn()`, which take care of managing the element content selection on focus. + Add the `_correctCaretPositionOnFocusAndSelectOnFocusOptions()` function that manage the `caretPositionOnFocus` and `selectOnFocus` options in order to prevent any conflict. + Strengthen `setElementSelection()` so that `element.firstChild` is checked for `null` value. + Add a table of contents to the readme and reorganize its chapters. ### 4.0.0-beta.14 + Add more bracket types to the `negativeBracketsTypeOnBlur` option ('〈,〉', '「,」', '⸤,⸥', '⟦,⟧', '‹,›' and '«,»') + Reformat the changelog, fix some typos + Modify the static `unformat()` signature to allow multiple options objects to be passed as arguments. Each more option object overwrite the previous ones. This allows to correctly unformat currencies that have a predefined option as its base, but has been slightly modified (ie. `AutoNumeric.unformat('241800,02 €', AutoNumeric.getPredefinedOptions().French, { digitGroupSeparator: AutoNumeric.options.digitGroupSeparator.noSeparator })`, and still get the right result). + Split the `_checkEmpty()` function into `_isElementValueEmptyOrOnlyTheNegativeSign()` and `_orderValueCurrencySymbolAndSuffixText()`. Both new functions only do one thing and one thing only, allowing the code to be rewrote in a clearer way. + Delete the `_checkEmpty()` function. + Simplify `_roundValue()` to make it more legible ; This is done by extracting `_roundCloseTo05()`, `_prepareValueForRounding()` and `_shouldRoundUp()`. + Remove an unnecessary `while` loop in `_stripAllNonNumberCharacters()` ### 4.0.0-beta.13 + Modify `init()` so that it allows the user to also pass an array of DOM elements, or a CSS selector as its first argument (cf. issue #388 comments) ### 4.0.0-beta.12 + Fix issue #434 Using `noSeparatorOnFocus` set to `noSeparator` shou