Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully convert autoNumeric to an ES6 module #399

Closed
AlexandreBonneau opened this issue Feb 4, 2017 · 1 comment
Closed

Fully convert autoNumeric to an ES6 module #399

AlexandreBonneau opened this issue Feb 4, 2017 · 1 comment

Comments

@AlexandreBonneau
Copy link
Member

AlexandreBonneau commented Feb 4, 2017

The idea is to use the AutoNumeric :

  • static methods to access default options and static functions,
  • class to instantiate AutoNumeric elements.

Those AutoNumeric elements will hold all the configuration variables and provide an API to manipulate the element value.

In the former case, we can use the AutoNumeric class directly to format/unformat numbers and strings, without having to use a DOM element.
In the latter case, we can use an already instantiated AutoNumeric object in order to clone its configuration for initializing another DOM element.

To sum up :

  • Use the AutoNumeric class as a static object to access default options and static methods,
  • Instantiate an AutoNumeric when you want to init an element
  • Those elements then provides the usual functions (ie. anElement.set(42))
  • You can use any AutoNumeric object to initialize other DOM elements with the same options configuration
  • All those elements share a common list on which you can use global commands that will be replicated on each individual AutoNumeric element.

Following is the proposed new API :

Initialization (Create an instance of the autoNumeric object)

anElement = new AutoNumeric(domElement); // With the default options
anElement = new AutoNumeric(domElement, { options }); // With one option object
anElement = new AutoNumeric(domElement).french(); // With one pre-defined language object
anElement = new AutoNumeric(domElement).french({ options });// With one pre-defined language object and additional options that will override those defaults

// ...or init and set the value in one call :
anElement = new AutoNumeric(domElement, 12345.789); // With the default options, and an initial value
anElement = new AutoNumeric(domElement, 12345.789, { options });
anElement = new AutoNumeric(domElement, '12345.789', { options });
anElement = new AutoNumeric(domElement, null, { options }); // With a null initial value
anElement = new AutoNumeric(domElement, 12345.789).french({ options });
anElement = new AutoNumeric(domElement, 12345.789, { options }).french({ options }); // Not really helpful, but possible

// The AutoNumeric constructor class can also accept a string as a css selector. Under the hood this use `QuerySelector` and limit itself to only the first element it finds.
anElement = new AutoNumeric('.myCssClass > input');
anElement = new AutoNumeric('.myCssClass > input', { options });
anElement = new AutoNumeric('.myCssClass > input', 12345.789);
anElement = new AutoNumeric('.myCssClass > input', 12345.789, { options });
anElement = new AutoNumeric('.myCssClass > input', null, { options }); // With a null initial value
anElement = new AutoNumeric('.myCssClass > input', 12345.789).french({ options });

Note: AutoNumeric also accepts a limited tag list that it will format on page load, but without adding any event listeners

Initialization of multiple AutoNumeric elements at once

Note: The previous notation $('query selector string').autoNumeric('init') was not deterministic since depending on the selector result (none, one or more elements), autoNumeric initialized an unknown number of elements.
With the new API featuring a class, using new AutoNumeric() to generate more than one AutoNumeric object is against all convention and should not be done.
In order to initialize multiple AutoNumeric elements at once, you'll need to know in advance that you want to initialize multiple elements and therefore retrieve an array as a result. This can be done by using the new notation (using a static method) :

// ...or init multiple DOM elements in one call (and possibly pass multiple values that will be mapped to each DOM element)
[anElement1, anElement2, anElement3] = AutoNumeric.multiple([domElement1, domElement2, domElement3], { options });
[anElement1, anElement2, anElement3] = AutoNumeric.multiple([domElement1, domElement2, domElement3], 12345.789, { options });
[anElement1, anElement2, anElement3] = AutoNumeric.multiple.french([domElement1, domElement2, domElement3], [12345.789, 234.78, null], { options });

// Special case, if a <form> element is passed (or any other 'parent' (or 'root') DOM element), then autoNumeric will initialize each child <input> elements recursively, ignoring those referenced in the `exclude` attribute
[anElement1, anElement2] = AutoNumeric.multiple({ rootElement: formElement }, { options });
[anElement1, anElement2] = AutoNumeric.multiple({ rootElement: formElement, exclude : [hiddenElement, tokenElement] }, { options });
[anElement1, anElement2] = AutoNumeric.multiple({ rootElement: formElement, exclude : [hiddenElement, tokenElement] }, [12345.789, null], { options });

// If the user wants to select multiple elements via a css selector, then he must use the `multiple` function. Under the hood `QuerySelectorAll` is used.
[anElement1, anElement2] = AutoNumeric.multiple('.myCssClass > input', { options }); // This always return an Array, even if there is only one element selected
[anElement1, anElement2] = AutoNumeric.multiple('.myCssClass > input', [null, 12345.789], { options }); // Idem above, but with passing the initial values too

Options update

// Options can be added/modified after the initialization
// Either by passing an options object that contains multiple options...
anElement.update({ moreOptions });
anElement.update(AutoNumeric.getLanguages().NorthAmerican); // Update the settings (and immediately reformat the element accordingly)
// ...or by changing the options one by one (or by calling a pre-defined option object)
anElement.options.minimumValue('12343567.89');
anElement.options.allowDecimalPadding(false);

// The option object can be accessed directly, thus allowing to query each options too
anElement.getSettings(); // Return the options object containing all the current autoNumeric settings in effect

Then use the usual functions on each autoNumeric-managed element

// AutoNumeric functions
anElement.set(42.76); // Set the value (that will be formatted immediately)
anElement.set(42.76, { options }); // Set the value and update the setting in one go
anElement.setUnformatted(42.76); // Set the value (that will not be formatted immediately)
anElement.setUnformatted(42.76, { options }); // Set the value and update the setting in one go (the value will not be formatted immediately)
anElement.get(); // Alias for the `.getNumericString()` function
anElement.getNumericString(); // Return the unformatted number as a string
anElement.getFormatted(); // Return the formatted string
anElement.getNumber(); // Return the unformatted number as a number
anElement.getLocalized(); // Return the localized unformatted number as a string
anElement.getLocalized(forcedOutputFormat); // Return the localized unformatted number as a string, using the outputFormat option override passed as a parameter
anElement.reformat(); // Force the element to reformat its value again (in case the formatting has been lost)
anElement.unformat(); // Remove the formatting and keep only the raw unformatted value in the element (as a numeric string)
anElement.unformatLocalized(); // Remove the formatting and keep only the localized unformatted value in the element
anElement.unformatLocalized(forcedOutputFormat); // Idem above, but using the outputFormat option override passed as a parameter
anElement.isPristine(); // Return `true` if the current value is the same as when the element got initialized
anElement.select(); // Select the formatted element content, based on the `selectNumberOnly` option
anElement.selectNumber(); // Select only the numbers in the formatted element content, leaving out the currency symbol, whatever the value of the `selectNumberOnly` option
anElement.selectInteger(); // Select only the integer part in the formatted element content, whatever the value of `selectNumberOnly`
anElement.selectDecimal(); // Select only the decimal part in the formatted element content, whatever the value of `selectNumberOnly`
anElement.clear(); // Reset the element value to the empty string '' (or the currency sign, depending on the `emptyInputBehavior` option value)
anElement.clear(true); // Reset the element value to the empty string '' as above, no matter the `emptyInputBehavior` option value

// Un-initialize the AutoNumeric element
anElement.remove(); // Remove the autoNumeric listeners from the element (previous name : 'destroy'). Keep the element content intact.
anElement.wipe(); // Remove the autoNumeric listeners from the element, and reset its value to ''
anElement.nuke(); // Remove the autoNumeric listeners from the element, and delete the DOM element altogether

// Node manipulation
anElement.node(); // Return the DOM element reference of the autoNumeric-managed element
anElement.parent(); // Return the DOM element reference of the parent node of the autoNumeric-managed element
anElement.detach(); // Detach the current AutoNumeric element from the shared 'init' list (which means any changes made on that local shared list will not be transmitted to that element anymore)
anElement.detach(otherAnElement); // Idem above, but detach the given AutoNumeric element, not the current one
anElement.attach(otherAnElement, reFormat = true); // Attach the given AutoNumeric element to the shared local 'init' list. When doing that, by default the DOM content is left untouched. The user can force a reformat with the new shared list options by passing a second argument to `true`.

Use any AutoNumeric element to format/unformat other numbers/DOM elements without having to specify the options each time

// You can use any existing AutoNumeric element to access its methods without having to specify the options since they are already set, and passing another DOM element :
anElement.formatOther(12345, { options }); // Same function signature that when using the AutoNumeric object directly (cf. below: `AutoNumeric.format`), but without having to pass the options
anElement.formatOther(domElement5, { options }); // Idem above, but apply the formatting to the DOM element content directly
anElement.unformatOther('1.234,56 €', { options }); // Same function signature that when using the AutoNumeric object directly (cf. below: `AutoNumeric.unformat`), but without having to pass the options
anElement.unformatOther(domElement5, { options }); // Idem above, but apply the unformatting to the DOM element content directly

Initialize other DOM Elements

// Once you have an AutoNumeric element already setup correctly with the right options, you can use it as many times you want to initialize as many other DOM elements as needed (this works only on elements that can be managed by autoNumeric) :
const anElement3 = anElement.init(domElement3); // Use an existing aN element to initialize another DOM element with the same options
// Whenever `init` is used to initialize other DOM element, a shared 'init' list of those elements is stored in the AutoNumeric objects.
anElement3 = anElement.init(domElement3, true); // If `true` is set as the second argument, then the newly generated AutoNumeric element will not share the same local element list as `anElement`

Perform actions globally on a shared list of AutoNumeric elements

// This list can then be used to perform global operations on all those AutoNumeric elements, with one function call :
anElement.global.set(2000); // Set the value 2000 in all the autoNumeric-managed elements that are shared on this element
anElement.global.setUnformatted(69);
[result1, result2, result3] = anElement.global.get(); // Return an array of results
[result1, result2, result3] = anElement.global.getNumericString(); // Return an array of results
[result1, result2, result3] = anElement.global.getFormatted(); // Return an array of results
[result1, result2, result3] = anElement.global.getNumber(); // Return an array of results
[result1, result2, result3] = anElement.global.getLocalized(); // Return an array of results
anElement.global.reformat();
anElement.global.unformat();
anElement.global.unformatLocalized();
anElement.global.unformatLocalized(forcedOutputFormat);
anElement.global.isPristine(); // Return `true` is *all* the autoNumeric-managed elements are pristine, if their raw value hasn't changed
anElement.global.isPristine(false); // Idem as above, but also checks that the formatted value hasn't changed
anElement.global.clear(); // Clear the value in all the autoNumeric-managed elements that are shared on this element
anElement.global.remove();
anElement.global.wipe();

// ...or use functions specifically designed for that global list
anElement.global.has(domElementOrAutoNumericObject); // Return `true` if the given AutoNumeric object (or DOM element) is in the local AutoNumeric element list
anElement.global.addObject(domElementOrAutoNumericObject); // Add an existing AutoNumeric object (or DOM element) to the local AutoNumeric element list, using the DOM element as the key
anElement.global.removeObject(domElementOrAutoNumericObject); // Remove the given AutoNumeric object (or DOM element) from the local AutoNumeric element list, using the DOM element as the key
anElement.global.empty(); // Remove all elements from the shared list, effectively emptying it
[anElement0, anElement1, anElement2, anElement3] = anElement.global.elements(); // Return an array containing all the AutoNumeric elements that have been initialized by each other
anElement.global.getList(); // Return the `Map` object directly
anElement.global.size(); // Return the number of elements in the local AutoNumeric element list

Form functions

// Special functions that really work on the parent <form> element, instead of the <input> element itself :
anElement.form(); // Return a reference to the parent <form> element, `null` if it does not exist
anElement.formNumericString(); // Return a string in standard URL-encoded notation with the form input values being unformatted
anElement.formFormatted(); // Return a string in standard URL-encoded notation with the form input values being formatted
anElement.formLocalized(); // Return a string in standard URL-encoded notation with the form input values, with localized values
anElement.formLocalized(forcedOutputFormat); // Idem above, but with the possibility of overriding the `outputFormat` option
anElement.formArrayNumericString(); // Return an array containing an object for each form <input> element, with the values as numeric strings
anElement.formArrayFormatted(); // Return an array containing an object for each form <input> element, with the values as formatted strings
anElement.formArrayLocalized(); // Return an array containing an object for each form <input> element, with the values as localized numeric strings
anElement.formArrayLocalized(forcedOutputFormat); // Idem above, but with the possibility of overriding the `outputFormat` option
anElement.formJsonNumericString(); // Return a JSON string containing an object representing the form input values. This is based on the result of the `formArrayNumericString()` function.
anElement.formJsonFormatted(); // Return a JSON string containing an object representing the form input values. This is based on the result of the `formArrayFormatted()` function.
anElement.formJsonLocalized(); // Return a JSON string containing an object representing the form input values. This is based on the result of the `formArrayLocalized()` function.
anElement.formJsonLocalized(forcedOutputFormat); // Idem above, but with the possibility of overriding the `outputFormat` option
anElement.formUnformat(); // Unformat all the autoNumeric-managed elements that are a child to the parent <form> element of this `anElement` input, to numeric strings
anElement.formUnformatLocalized(); // Unformat all the autoNumeric-managed elements that are a child to the parent <form> element of this `anElement` input, to localized strings
anElement.formReformat(); // Reformat all the autoNumeric-managed elements that are a child to the parent <form> element of this `anElement` input

// The following functions can either take a callback, or not. If they don't, the default `form.submit()` function will be called.
anElement.formSubmitNumericString(callback); // Run the `callback(value)` with `value` being equal to the result of `formNumericString()`
anElement.formSubmitFormatted(callback); // Run the `callback(value)` with `value` being equal to the result of `formFormatted()`
anElement.formSubmitLocalized(callback); // Run the `callback(value)` with `value` being equal to the result of `formLocalized()`
anElement.formSubmitLocalized(forcedOutputFormat, callback); // Idem above, but with the possibility of overriding the `outputFormat` option

// For the following methods, the callback is mandatory
anElement.formSubmitArrayNumericString(callback); // Run the `callback(value)` with `value` being equal to the result of `formArrayNumericString()`
anElement.formSubmitArrayFormatted(callback); // Run the `callback(value)` with `value` being equal to the result of `formArrayFormatted()`
anElement.formSubmitArrayLocalized(callback, forcedOutputFormat); // Idem above, but with the possibility of overriding the `outputFormat` option
anElement.formSubmitJsonNumericString(callback); // Run the `callback(value)` with `value` being equal to the result of `formJsonNumericString()`
anElement.formSubmitJsonFormatted(callback); // Run the `callback(value)` with `value` being equal to the result of `formJsonFormatted()`
anElement.formSubmitJsonLocalized(callback, forcedOutputFormat); // Idem above, but with the possibility of overriding the `outputFormat` option

Static methods

// the AutoNumeric object also provide static methods :
AutoNumeric.validate({ options }); // Check if the given option object is valid, and that each option is valid as well. This throws an error if it's not.
AutoNumeric.areSettingsValid({ options }); // Return `true` if the `options` are valid settings
AutoNumeric.getDefaultConfig(); // Return the default autoNumeric settings 
AutoNumeric.getLanguages(); // Return all the predefined language options in one object
AutoNumeric.getLanguages().French; // Return a specific pre-defined language options object
AutoNumeric.format(12345.21, { options }); // Format the given number (or numeric string) with the given options. This returns the formatted value as a string.
AutoNumeric.format('12345.21', { options }); // Idem as above
AutoNumeric.format(domElement, { options }); // ..or format the `domElement` value with the given options and returns the formatted value as a string. This does *not* update that element value.
AutoNumeric.formatAndSet(domElement, { options }); // Format the `domElement` value with the given options and returns the formatted value as a string. This function does update that element value with the newly formatted value in the process.
AutoNumeric.unformat('1.234,56 €', { options }); // Unformat the given formatted string with the given options. This returns a numeric string.
AutoNumeric.unformat(domElement, { options }); // ..or unformat the `domElement` value with the given options and returns the unformatted numeric string. This does *not* update that element value.
AutoNumeric.unformatAndSet(domElement, { options }); // Unformat the `domElement` value with the given options and returns the unformatted value as a numeric string. This function does update that element value with the newly unformatted value in the process.
AutoNumeric.unformatAndSet(referenceToTheDomElement); // Recursively unformat all the autoNumeric-managed elements that are a child to the `referenceToTheDomElement` element given as a parameter (this is usually the parent `<form>` element)
AutoNumeric.reformatAndSet(referenceToTheDomElement); // Recursively format all the autoNumeric-managed elements that are a child to the `referenceToTheDomElement` element given as a parameter (this is usually the parent `<form>` element), with the settings of each AutoNumeric elements.
AutoNumeric.localize('1.234,56 €', { options }); // Unformat and localize the given formatted string with the given options. This returns a string.
AutoNumeric.localize(domElement, { options }); // Idem as above, but return the localized DOM element value. This does *not* update that element value.
AutoNumeric.localizeAndSet(domElement, { options }); // Unformat and localize the `domElement1` value with the given options and returns the localized value as a string. This function does update that element value with the newly localized value in the process.
AutoNumeric.test(domElement); // Test if the given domElement is already managed by AutoNumeric (if it is initialized)
AutoNumeric.version(); // Return the autoNumeric version number (for debugging purpose)

Function chaining

// All those functions can be chained
anElement.set(42)
         .getNumber(callback1)
         .update({ options })
         .formSubmitJsonNumericString(callback2)
         .clear();

Note: This proposed API is not final and can (will) change any time soon

@AlexandreBonneau AlexandreBonneau created this issue from a note in autoNumeric v4.0.0 (To convert to issue) Feb 4, 2017
@AlexandreBonneau AlexandreBonneau self-assigned this Feb 4, 2017
@AlexandreBonneau AlexandreBonneau changed the title Finish converting autoNumeric to an ES6 module Fully convert autoNumeric to an ES6 module Feb 4, 2017
@AlexandreBonneau AlexandreBonneau moved this from To convert to issue to Opened in autoNumeric v4.0.0 Feb 4, 2017
@AlexandreBonneau AlexandreBonneau moved this from Opened to In Progress in autoNumeric v4.0.0 Feb 4, 2017
AlexandreBonneau added a commit that referenced this issue Feb 27, 2017
Fix issue #398 Finish removing all jQuery dependencies
Fix issue #244 [Feature request] Remove the jQuery dependency

Add an entry point `src/main.js` for bundling the library.
Split the library into 3 files ;
- `autoNumeric.js`, which contains the AutoNumeric class,
- `AutoNumericEnum.js` which contains the enumerations used by AutoNumeric, and
- `AutoNumericHelper.js` which contains the AutoNumericHelper class which provides static helper functions.

Extract the `allowedTagList`, `keyCode` and `keyName` into `AutoNumericEnum`.
Add the `isEmptyString`, `isNumberOrArabic`, `isFunction`, `isElement`, `isInputElement`, `arabicToLatinNumbers`, `triggerEvent`, `randomString`, `getElementValue`, `setElementValue`, `cloneObject`, `camelize`, `text`, `setText` and `filterOut` functions to the helper functions.
Move the `preparePastedText`, `runCallbacksFoundInTheSettingsObject`, `maximumVMinAndVMaxDecimalLength`, `stripAllNonNumberCharacters`, `toggleNegativeBracket`, `convertToNumericString`, `toLocale`, `modifyNegativeSignAndDecimalCharacterForRawValue`, `modifyNegativeSignAndDecimalCharacterForFormattedValue`, `checkEmpty`, `addGroupSeparators`, `truncateZeros`, `roundValue`, `truncateDecimal`, `checkIfInRangeWithOverrideOption` functions into the AutoNumeric object.
Improve the `character()` method to take into account the quirks of some obsolete browsers.
Remove the `getCurrentElement()` function since we now only need to access the `this.domElement` property.
Remove the `AutoNumericHolder` class and the `getAutoNumericHolder()` function since we are now using the AutoNumeric class as the 'property holder'.

Add multiple ways to initialize an AutoNumeric element (cf. the AutoNumeric constructor and the `_setArgumentsValues()` method).
Simplify the input type and tag support check.
Add the `serializeSpaces` option that allows the user to defines how the serialize function will managed the spaces, either by converting them to `'%20'`, or to the `'+'` string, the latter now being the default.
Add the `noEventListeners` option that allows the user to initialize an AutoNumeric `<input>` element without adding any AutoNumeric event listeners.
Add the `readOnly` option to the settings that allow the `<input>` element to be set to read-only on initialization.
Add a feature where all AutoNumeric-managed elements in a page share a common list.
Add a feature where 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).
Add a `isPristine()` method to test if an AutoNumeric-managed element `value`/`textContent` has been changed since its initialization.
Rename `unset` to `unformat`.
Rename `reSet` to `reformat`.
Add an `unformatLocalized()` function to unformat the element value while using the `outputFormat` setting.
Add a `clear()` method to empty the element value.
Add a `nuke()` method to remove the DOM element from the DOM tree.
Add a `.global.has()` method to check if the given AutoNumeric object (or DOM element) is in the local AutoNumeric element list.
Add a `.global.addObject()` method that adds an existing AutoNumeric object (or DOM element) to the local AutoNumeric element list.
Add a `.global.removeObject()` method that removes the given AutoNumeric object (or DOM element) from the local AutoNumeric element list.
Add a `.global.empty()` method to remove all elements from the shared list.
Add a `.global.elements()` method to retrieve all the AutoNumeric object that share the same local list.
Add a `.global.getList()` method to retrieve the local AutoNumeric element list.
Add one function for updating each option individually (ie. anElement.options.decimalCharacter('.')) instead of having to pass an object.
Add a `version()` method to output the current AutoNumeric version (for debug purpose).
Fix the `set()` method so that the `rawValue` is updated when the value is set to `''`.
Add a `setUnformatted()` method to set the value given value directly as the DOM element value, without formatting it beforehand.
Deprecate the `get()` method to the renamed `getNumericString()` which bares more meaning.
Add a `getFormatted()` method to retrieve the current formatted value of the AutoNumeric element as a string.
Add a `getNumber()` method that returns the element unformatted value as a real Javascript number.
Add a `getLocalized()` method that returns the unformatted value, but following the `outputFormat` setting.
Add a `unformatLocalized()` method that unformats the element value by removing the formatting and keeping only the localized unformatted value in the element.
Add a `selectNumber()` method that select only the numbers in the formatted element content, leaving out the currency symbol, whatever the value of the `selectNumberOnly` option.
Add a `selectInteger()` method that select only the integer part in the formatted element content, whatever the value of the `selectNumberOnly` option.
Add a `selectDecimal()` method that select only the decimal part in the formatted element content, whatever the value of `selectNumberOnly`.
Add a `node()` method that returns the DOM element reference of the autoNumeric-managed element.
Add a `parent()` method that returns the DOM element reference of the parent node of the autoNumeric-managed element.
Add a `detach()` method that detach the current AutoNumeric element from the shared local 'init' list.
Add an `attach()` method that attach the given AutoNumeric element to the shared local 'init' list.
Add a `formatOther()` method that format and return the given value, or set the formatted value into the given DOM element if one is passed as an argument.
Add an `unformatOther()` method that unformat and return the raw numeric string corresponding to the given value, or directly set the unformatted value into the given DOM element if one is passed as an argument.
Add an `init()` method that allows to use the current AutoNumeric element settings to initialize the DOM element given as a parameter. This effectively *link* the two AutoNumeric element by making them share the same local AutoNumeric element list.
Add a `form()` method that return a reference to the parent <form> element if it exists, otherwise return `null`.
Add a `formNumericString()` method that returns a string in standard URL-encoded notation with the form input values being unformatted.
Add a `formFormatted()` method that returns a string in standard URL-encoded notation with the form input values being formatted.
Add a `formLocalized()` method that returns a string in standard URL-encoded notation with the form input values, with localized values.
Add a `formArrayNumericString()` method that returns an array containing an object for each form <input> element.
Add a `formArrayFormatted()` method that returns an array containing an object for each form <input> element, with the value formatted.
Add a `formArrayLocalized()` method that returns an array containing an object for each form <input> element, with the value localized.
Add a `formJsonNumericString()` method that returns a JSON string containing an object representing the form input values.
Add a `formJsonFormatted()` method that returns a JSON string containing an object representing the form input values, with the value formatted.
Add a `formJsonLocalized()` method that returns a JSON string containing an object representing the form input values, with the value localized.
Add a `formUnformat()` method that unformat all the autoNumeric-managed elements that are a child of the parent <form> element of this DOM element, to numeric strings.
Add a `formUnformatLocalized()` method that unformat all the autoNumeric-managed elements that are a child of the parent <form> element of this DOM element, to localized strings.
Add a `formReformat()` method that reformat all the autoNumeric-managed elements that are a child of the parent <form> element of this DOM element.
Add a `formSubmitNumericString()` method that convert the input values to numeric strings, submit the form, then reformat those back.
Add a `formSubmitFormatted()` method that submit the form with the current formatted values.
Add a `formSubmitLocalized()` method that convert the input values to localized strings, submit the form, then reformat those back.
Add a `formSubmitArrayNumericString()` method that generate an array of numeric strings from the `<input>` elements, and pass it to the given callback.
Add a `formSubmitArrayFormatted()` method that generate an array of the current formatted values from the `<input>` elements, and pass it to the given callback.
Add a `formSubmitArrayLocalized()` method that generate an array of localized strings from the `<input>` elements, and pass it to the given callback.
Add a `formSubmitJsonNumericString()` method that generate a JSON string with the numeric strings values from the `<input>` elements, and pass it to the given callback.
Add a `formSubmitJsonFormatted()` method that generate a JSON string with the current formatted values from the `<input>` elements, and pass it to the given callback.
Add a `formSubmitJsonLocalized()` method that generate a JSON string with the localized strings values from the `<input>` elements, and pass it to the given callback.
Add a static `test()` method that if the given domElement is already managed by AutoNumeric (if it has been initialized on the current page).
Add multiple private methods to create and delete a global list of AutoNumeric objects (via a WeakMap), as well as the methods to add and remove elements to that list.
Add multiple private methods to manage the local enumerable list of AutoNumeric objects that are initialized together and share a common local list.
Add the private methods `_mergeSettings()` and `_cloneAndMergeSettings()` to do what they are named about.
Modify the static `format()` method so that it formats the given number (or numeric string) with the given options, and returns the formatted value as a string.
Add a static `formatAndSet()` method that format the given DOM element value, and set the resulting value back as the element value.
Modify the static `unformat()` method so that it unformats the given formatted string with the given options, and returns a numeric string.
Add a static `unformatAndSet()` method that unformat the given DOM element value, and set the resulting value back as the element value.
Add a static `localize()` method that unformat and localize the given formatted string with the given options, and returns a numeric string.
Add a static `isManagedByAutoNumeric()` method that returns `true` is the given DOM element has an AutoNumeric object that manages it.
Add a static `getAutoNumericElement()` method that returns the AutoNumeric object that manages the given DOM element.
Add the `french()`, `northAmerican()`, `british()`, `swiss()`, `japanese()`, `spanish()` and `chinese()` methods that update the settings to use the named pre-defined language options.
Convert some cryptic ternary statements to if/else block.
Remove the unknown parameter `setReal` from some functions.
Remove the need to pass around the settings in many functions signatures (using `this.settings` directly).
Rename the temporary variables created by coping some settings, with the new option names.
Correct the warning shown when using `isNan()` on non-number elements like strings.
Keep the focus status of the DOM element in the new `this.isFocused` variable.
Use the `getElementValue()` function to retrieve the element `value` or `textContent` (depending if the element in an <input> or another tag), which allow AutoNumeric to perform some operations on non-input elements too. This is the first changes needed for the goal of managing the non-input tags with `contentEditable` with AutoNumeric.
Use the `getElementValue()` function as well in order to be able to set the `value` or `textContent` transparently where needed.
Rename `_updateAutoNumericHolderProperties()` to `_updateInternalProperties()`.
Complete some JSDoc to be more precise on the event or element types. This helps for IDE autocompletion.
Rewrite completely how AutoNumeric test if the given DOM element is supported or not (by using the new `_checkElement()` method). This simplify the process by calling the new `_isElementTagSupported()`, `_isInputElement()` and `_isInputTypeSupported()` functions which respect the separation of concerns.
The `_formatDefaultValueOnPageLoad()` method now accepts a 'forced' initial value instead of the default one.
Remove the tests about the input type or element support from the `set()` methods, since those cannot change once AutoNumeric has been initialized, simplifying the code.
Remove duplicated tests (ie. `settings.formatOnPageLoad` inside the `formatDefaultValueOnPageLoad()` function that is only called if `settings.formatOnPageLoad` is already set).
Rename the `getInitialSettings()` method to `_setSettings()`.
Use array destructuring to give more meaningful names to the data returned by the `_getSignPosition()` function.
Add a private `_serialize()` function that take care of serializing the form data into multiple output as needed, which is called by the `_serializeNumericString()`, `_serializeFormatted()`,`_serializeLocalized()`, `_serializeNumericStringArray()`, `_serializeFormattedArray()` and `_serializeLocalizedArray()` methods.
The default settings are now exposed on the AutoNumeric class as a static object `AutoNumeric.defaultSettings`.
Add the static `AutoNumeric.options` object that gives access to all the possible options values, with a semantic name (handy for IDE autocompletion).
The pre-defined language options objects are now accessible via the static `AutoNumeric.languageOptions` object.
Add the static `AutoNumeric.multiple()` function that allows to initialize numerous AutoNumeric object (on numerous DOM elements) in one call (and possibly pass multiple values that will be mapped to each DOM element).

Add end-to-end tests for initializing non-<input> tags.
Add e2e tests for initializing elements with the `noEventListeners` or `readOnly` options.
Convert the end-to-end tests to the new API v3.
Convert the unit tests to the new API v3.
Add unit tests for the `serializeSpaces`, `noEventListeners` and `readOnly` options.
Fix the unit tests checking that the `rawValue` was correctly set when using `getSettings()`.
Add unit tests to check the `.global.*` methods.
Add unit tests to check the `AutoNumeric.multiple()` methods.
Add unit tests to check the `selectDecimal`, `selectInteger`, `reformat`, `unformat` and `unformatLocalized` methods.
Add unit tests to check the `.form*` methods.
Add the `babel-plugin-transform-object-assign` dev dependency in order to be able to use `Object.assign()` in the ES6 source.
Update the README with the new API.

Signed-off-by: Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
@AlexandreBonneau
Copy link
Member Author

Check the updated README.md for more info on the new API!

@AlexandreBonneau AlexandreBonneau moved this from In Progress to Done in autoNumeric v4.0.0 Feb 27, 2017
@AlexandreBonneau AlexandreBonneau moved this from Done to Verified in autoNumeric v4.0.0 Mar 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

1 participant