UNPKG

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

646 lines (540 loc) 118 kB
## Changelog for AutoNumeric ## 4.10.8 + Updates the npm version that includes the #673 fix ## 4.10.7 + Fixes #673 Handle composition events to fix strange behavior during input composition (#797) ### 4.10.6 + Fixes #795 Error when resetting a form that has an input with name="id" ### 4.10.5 + Adds the native `focus` event to the test page + Fixes cut event handling when `eventKey` `x` is in uppercase ### 4.10.4 + Fixes wrong npm deployment for `4.10.3` ### 4.10.3 + Fixes the handling of a wheel event with a deltaY equal to zero, for real this time ;) ### 4.10.2 + Bumps the AutoNumeric version to include the new index.d.ts file + Fixes #773 Typescript types in index.d.ts missing/wrong ### 4.10.1 + Fixes #776 On rapid event wheel emissions, deltaY of value 0 can be emitted and makes AutoNumeric throw an error + Adds more visibly the current AutoNumeric version being tested on the end-to-end testing page ### 4.10.0 + Drops IE11 support + Removes IE11 hacks, and updates part of the code that was not using modern tech because of obsolete browsers support + Removes the `Array.from` and `CustomEvent` polyfills ### 4.9.0 + Closes #728 Unable to group by 2 using digital group spacing options + This version modifies the `AutoNumeric.options.digitalGroupSpacing.two` option, which is now named `AutoNumeric.options.digitalGroupSpacing.twoThree` + The `AutoNumeric.options.digitalGroupSpacing.two` now effectively groups only by 2 (and not by 2 and 3 like before for India's numbering system) ### 4.8.4 + Fixes #768 `unformatOnSubmit` does not unformat fields located outside of form DOM subtree + Updates the function that search for form children to also include the `contenteditable` elements ### 4.8.3 + Fixes #718 When `emptyInputBehavior` is set to `null`, then `getNumber()` returns `0` when no value has been set before + Updates the `yarn clean:log` command to clean the logs from the newer webdriver.io version + Fixes #765 `change` event is not triggered when dragging value into a text input ### 4.8.2 + Fixes PR #731 by avoiding "Forced reflow" when calling the `_historyTableAdd()` function ### 4.8.1 + Fixes #763 Copyright banner in the minimized distribution file is undefined + Removes unused wdio script from package.json ### 4.8.0 + Adds #709 Feature request: Disallow toggling the negative/positive sign with '+' and '-' keypress + This adds a new option `negativePositiveSignBehavior` for the managing the '-' and '+' key behavior + Setting `negativePositiveSignBehavior` to `true` will allow the toggling, while setting it to `false` will disable it; this means that when hitting the '-' key, the value will always be set to its negative value, and hitting the '+' key will always set the element to its positive value (given the minimum and maximum value allows this) + Do note that the default behavior is changed in this version, where toggling between the positive and negative value with the '-' or '+' keys is not activated by default. If you want to use the previous behavior, please set `negativePositiveSignBehavior: AutoNumeric.options.negativePositiveSignBehavior.toggle` in your options' configuration. + Updates the existing end-to-end tests that relied on the toggle behavior + Fixes the incorrect error message when setting an invalid `positiveSignCharacter` option + Attempts to fix the 'node: 18' error from Travis CI ### 4.7.0 + Fixes #719 Feature request: Up and down arrow keys behavior matching standard number input + Adds 2 new options to control how the up and down arrow keys behave: `modifyValueOnUpDownArrow` and `upDownStep` ### 4.6.3 + Fixes #721 AutoNumeric.set() breaks internal state when string-value has leading or trailing whitespace + Fixes all the remaining end-to-end tests with the latest Webdriver.io version + Removes the remnants of PhantomJS hacks (#384) + Updates the Travis CI configuration + Fixes the caret positioning in some specific cases + Fixes the lint issues in the wdio config file + Fixes the webpack production config to correctly generate gzipped dist files ### 4.6.2 + Fixes issue #757 Converted scientific numbers returns NaN when using `formArrayNumericString()` + Fixes warning messages in the IDE ### 4.6.1 + Updates all the dependencies + Removes the PhantomJS dependency in favor of Puppeteer + Fixes and cleans the Karma configuration files to support v6.4.1 + Fixes and cleans the Webpack configuration files to support v5.75.0 + Fixes the failing unit tests on the `validate()` function for the `allowDecimalPadding` option + Updates the Webdriverio configuration to v8 + Updates the Webdriver end-to-end tests to v8, i.e. removing the `@wdio/sync` package in favor of using async/await everywhere, and updating all the `keys()` calls to use the Webdriver `Key` object, and arrays of individual characters + Adds unit tests for feature request #741 + Completes the `validate()` function with additional tests for the new `allowDecimalPadding` option as a number + Fixes #761 Undo and redo actions are done twice, on Z and Control KeyUp events + Fixes missing variable update in #739 (`this.onGoingRedo`) + Fixes the warning message when a faulty `styleRules` callback is passed as a parameter + Fixes typos and grammar in comments + Fixes #734 Fire change event onBlur only if number is changed (#735) + Fixes #753 Correct invalid JS imports + Fixes #758 Adding missing predefined options to typescript interface file + Update the readme with the new documentation website + Fixes #739 Add CTRL+Y shortcut for redo + Fixes the currency symbol for Brazilian real + Fixes #697 Currency can be deleted (#725) + Updates the README related to PR #742 + Fixes #741 + Ability to set a numeric allowDecimalPadding (#742) + Adds default export to modules (#747) + Fixes #737 Undo/redo not firing input event + Fixes #684 Caret always set far right when deleting or inserting numbers using $ (#716) + Fixes unit tests following the changes in `v4.6.0` ### 4.6.0 + Adds a new option `invalidClass`, which default to `an-invalid`, that defines the CSS class name to use when a contenteditable-enabled element value is invalid + Adds a new option value `'invalid'` for the `overrideMinMaxLimits` option, that will allow users to enter out-of-bound numbers + Fixes #543 Allow users to enter out-of-bound numbers, outside of the `minimumValue` and `maximumValue` range + This allows users to type temporary invalid numbers when the `minimumValue` is superior to `0`, or the `maximumValue` is inferior to `0` + While in this out-of-bound state, the element validity status is set to `invalid` + Users can then target the CSS `:invalid` and/or `:valid` state as they wish to display a visual feedback as needed + Do note that contenteditable-enabled elements cannot have a validity state set, so AutoNumeric instead sets by default the `an-invalid` CSS class on such 'invalid' elements + Whenever the user type an invalid number (out of range), the new `'autoNumeric:invalidValue'` event is sent. When the value is corrected, the new `'autoNumeric:correctedValue'` event is sent. + Beware; To reduce complexity, the `'autoNumeric:invalidValue'` event as well as the `'autoNumeric:minExceeded'` or `'autoNumeric:maxExceeded'` events are now sent up to three times for a single input; on keypress, keyup and blur + From now on, whenever the user sets a `minimumValue` higher than `0`, or a `maximumValue` lower than `0`, a warning will be displayed in the console telling him to perhaps use the `overrideMinMaxLimits` `invalid` option. For information, the `overrideMinMaxLimits` `doNotOverride` is still the default behavior. + Simplify the min and max range tests with the new private `_isWithinRangeWithOverrideOption()` function + Fixes the bug where you could always clear the input even if the limit were preventing you to do so (the last valid value was then set back on blur). Now AutoNumeric correctly prevents you to clear the input if the resulting value is out-of-bound. + Fixes #676 36 errors in index.d.ts when using with typescript + TypeScript users should now remove the `declare module 'autonumeric';` line from their script (cf. PR #677) + Removes node 6 from the CI tests (cf. PR #678) + Fixes the detection of wheel events when using a touchpad/trackball (cf. PR #672) ### 4.5.13 + Fixes #675 The caret position is wrongly positioned when setting the raw value to zero on numbers with a prefix currency symbol (The bug was introduced in `v4.5.9` with the fix for #647) ### 4.5.12 + Synchronizes the AutoNumeric version with the published npm one ### 4.5.11 + Adds a typescript definitions file to the library + Fixes some errors in the typescript definitions file and fixes the indentation ### 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