Enables the AutoNumeric feature for the given element.
The DOM element must be one of the allowed elements. Allowed elements are <input>
, as well as some
other text-containing elements such <div>
. See the documentation for the full list.
When not an input
element, the element may have the contenteditable
set. If it does, all
entered values are formatted according to the given options. Otherwise, the formatted value is
set once and no further edits are possible.
Either one of the allowed elements, or a CSS selector string for a single element.
Initial value, when null
, the value of the DOM element is used.
Settings for AutoNumeric.
Enables the AutoNumeric feature for the given element.
The DOM element must be one of the allowed elements. Allowed elements are <input>
, as well as some
other text-containing elements such <div>
. See the documentation for the full list.
When not an input
element, the element may have the contenteditable
set. If it does, all
entered values are formatted according to the given options. Otherwise, the formatted value is
set once and no further edits are possible.
Either one of the allowed elements, or a CSS selector string for a single element.
Settings for AutoNumeric.
Whenever init is used to initialize other DOM elements, a shared local init
list of those elements is stored in
the AutoNumeric instances.
This allows for neat things like modifying all those linked AutoNumeric elements globally, with only one call.
Use this property to access the handler that provides methods to modify all linked elements.
Contains convenience methods to update individual options, and also allows the options to be reset.
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
.
Element to attach.
Whether to reformat the value after the element was attached. Defaults to true
.
This instance for chaining method calls.
Update the settings to use the Brazilian pre-defined language options. Those pre-defined options can be overridden by passing an option object as a parameter.
Optional options to override the pre-defined options.
This instance for chaining method calls.
Update the settings to use the British pre-defined language options. Those pre-defined options can be overridden by passing an option object as a parameter.
Optional options to override the pre-defined options.
This instance for chaining method calls.
Update the settings to use the Chinese pre-defined language options. Those pre-defined options can be overridden by passing an option object as a parameter.
Optional options to override the pre-defined options.
This instance for chaining method calls.
Reset the element value either to the empty string '', or the currency sign, depending on the emptyInputBehavior
option value.
If you set the forceClearAll
argument to true
, then the emptyInputBehavior
option is overridden
and the whole input is cleared, including any currency sign.
true
to clear the the entire input, including the currency sign.
This instance for chaining method calls.
Detach the current AutoNumeric element from the shared local init
list.
This means any changes made on that local shared list will not be transmitted to that element anymore.
Note: The user can provide another AutoNumeric element, and detach this one instead of the current one.
Element to detach.
This instance for chaining method calls.
Return a reference to the parent
If the parent form element as already been found, this directly return a reference to it.
However, you can force AutoNumeric to search again for its reference by passing true
as a parameter to this method.
This method updates the this.parentForm
attribute.
In either case, whenever a new parent form is set for the current AutoNumeric element, we make sure to update the anCount and anFormHandler attributes on both the old form and the new one (for instance in case the user moved the input elements with appendChild()
since AutoNumeric cannot not detect that).
Whether to force a new search for the parent <form>
element, discarding any previously found one. Defaults to false
.
The form element containing this AutoNumeric element, if any.
Return an array containing an object for each form element. The name of each pair is the name of the DOM elements. The value is is formatted value of each AutoNumeric input.
The formatted values.
Return an array containing an object for each form element. The name of each pair is the name of the DOM elements.
The value is is localized value of each AutoNumeric input.
Values might be a string or a number, depending on the outputFormat
option.
If set to something different from null
, then this is used as an override for the outputFormat
option
The localized values.
Return an array containing an object for each form element. The name of each pair is the name of the DOM elements. The value is is stringified numeric value of each AutoNumeric input.
The numerical values.
Return a string in standard URL-encoded notation with the form input values being formatted.
The formatted string.
Return an array containing an object for each form element, stringified as a JSON string. The name of each pair is the name of the DOM elements. The value is is formatted value of each AutoNumeric input.
The formatted values.
Return an array containing an object for each form element, stringified as a JSON string. The name of each pair is the name of the DOM elements. The value is is localized value of each AutoNumeric input.
If set to something different from null
, then this is used as an override for the outputFormat
option.
The localized values.
Return an array containing an object for each form element, stringified as a JSON string. The name of each pair is the name of the DOM elements. The value is is localized value of each AutoNumeric input.
The numerical values.
Return a string in standard URL-encoded notation with the form input values, with localized values.
The default output format can be overridden by passing the option as a parameter.
If set to something different from null
, then this is used as an override for the outputFormat
option
The localized string.
Return a string in standard URL-encoded notation with the form input values being unformatted.
This string can be used as a query for instance.
The formatted string.
Reformat all the autoNumeric-managed elements that are a child of the parent
This instance for chaining method calls.
Generate an array of the current formatted values from the <input>
elements, and pass it to the given callback.
Under the hood, the array is generated via a call to formArrayFormatted()
.
Callback to invoke with the values.
This instance for chaining method calls.
Generate an array of localized strings from the <input>
elements, and pass it to the given callback.
Under the hood, the array is generated via a call to formArrayLocalized()
.
Values might be a string or a number, depending on the outputFormat
option.
Callback to invoke with the values.
If set to something different from null
, then this is used as an override for the outputFormat
option.
This instance for chaining method calls.
Generate an array of numeric strings from the <input>
elements, and pass it to the given callback.
Under the hood, the array is generated via a call to formArrayNumericString()
.
Callback to invoke with the values.
This instance for chaining method calls.
Generate a JSON string with the current formatted values from the <input>
elements, and pass it to the given callback.
Under the hood, the array is generated via a call to formJsonFormatted()
.
Callback to invoke with the values.
This instance for chaining method calls.
Generate a JSON string with the localized strings values from the <input>
elements, and pass it to the given callback.
Under the hood, the array is generated via a call to formJsonLocalized()
.
Callback to invoke with the values.
If set to something different from null
, then this is used as an override for the outputFormat
option.
This instance for chaining method calls.
Generate a JSON string with the numeric strings values from the <input>
elements, and pass it to the given callback.
Under the hood, the array is generated via a call to formJsonNumericString()
.
Callback to invoke with the values.
This instance for chaining method calls.
Unformat all the autoNumeric-managed elements that are a child of the parent
This instance for chaining method calls.
Unformat all the autoNumeric-managed elements that are a child of the parent <form>
element of
this DOM element, to localized strings
This instance for chaining method calls.
Update the settings to use the French pre-defined language options. Those pre-defined options can be overridden by passing an option object as a parameter.
Optional options to override the pre-defined options.
This instance for chaining method calls.
Return the current formatted value of the AutoNumeric element as a string.
Optional callback that, when given, is called with the value and the AutoNumeric instance.
The formatted value.
Returns the unformatted value, but following the outputFormat
setting, which means the output can either be:
'number'
is used).By default the returned values are an ISO numeric string "1234.56" or "-1234.56" where the decimal character is a period.
Check the outputFormat
option definition for more details.
Override for the outputFormat
option.
Optional callback that, when given, is called with the value and the AutoNumeric instance.
The localized value.
Returns the unformatted value, but following the outputFormat
setting, which means the output can either be:
'number'
is used).By default the returned values are an ISO numeric string "1234.56" or "-1234.56" where the decimal character is a period.
Check the outputFormat
option definition for more details.
Optional callback that, when given, is called with the value and the AutoNumeric instance.
The localized value.
Return the element unformatted value as a real JavaScript number.
Optional callback that, when given, is called with the value and the AutoNumeric instance.
The number value.
Return the unformatted value as a string.
This can also return null
if rawValue
is null.
Optional callback that, when given, is called with the value and the AutoNumeric instance.
The numerical value.
Use the current AutoNumeric element settings to initialize the DOM element(s) given as a parameter.
Doing so will link the AutoNumeric elements together since they will share the same local AutoNumeric element list.
(cf. prototype pattern : https://en.wikipedia.org/wiki/Prototype_pattern)
You can init
either a single DOM element (in that case an AutoNumeric object will be returned), or an array of DOM elements or a string that will be used as a CSS selector. In the latter cases, an array of AutoNumeric objects will then be returned (or an empty array if nothing gets selected by the CSS selector).
Use case : 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.
Note: this works only on elements that can be managed by autoNumeric.
A single element to initialize.
If set to false
, then the newly generated AutoNumeric element will not share the same local element list.
The initialized AutoNumeric instance.
Use the current AutoNumeric element settings to initialize the DOM element(s) given as a parameter.
Doing so will link the AutoNumeric elements together since they will share the same local AutoNumeric element list.
(cf. prototype pattern : https://en.wikipedia.org/wiki/Prototype_pattern)
You can init
either a single DOM element (in that case an AutoNumeric object will be returned), or an array of DOM elements or a string that will be used as a CSS selector. In the latter cases, an array of AutoNumeric objects will then be returned (or an empty array if nothing gets selected by the CSS selector).
Use case : 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.
Note: this works only on elements that can be managed by autoNumeric.
A list of elements, or a string representing a CSS selector.
If set to false
, then the newly generated AutoNumeric element will not share the same local element list.
The initialized AutoNumeric instances.
Return true
if all the autoNumeric-managed elements are pristine, if their raw value hasn't changed.
By default, this returns true
if the raw unformatted value is still the same even if the formatted one has changed (due to a configuration update for instance).
If set to true
, the pristine value is done on the raw unformatted value, not the formatted one. If set to false
, this also checks that the formatted value hasn't changed.
If this instance is pristine.
Update the settings to use the Japanese pre-defined language options. Those pre-defined options can be overridden by passing an option object as a parameter.
Optional options to override the pre-defined options.
This instance for chaining method calls.
Return the DOM element reference of the autoNumeric-managed element. The exact type depends on the element that on which AutoNumeric was initialized - AutoNumeric supports input elements as well as other content editable elements such as div elements.
Update the settings to use the North American pre-defined language options. Those pre-defined options can be overridden by passing an option object as a parameter.
Optional options to override the pre-defined options.
This instance for chaining method calls.
Remove the autoNumeric data and event listeners from the element, and delete the DOM element altogether
Return the DOM element reference of the parent node of the AutoNumeric managed element
The parent of the AutoNumeric element.
Force each element of the local AutoNumeric element list to reformat its value
This instance for chaining method calls.
Remove the autoNumeric data and event listeners from the element, but keep the element content intact.
This also clears the value from sessionStorage (or cookie, depending on browser supports).
Note: this does not remove the formatting.
Select the formatted element content, based on the selectNumberOnly
option
This instance for chaining method calls.
Select only the decimal part in the formatted element content, whatever the value of selectNumberOnly
Multiple cases are possible:
This instance for chaining method calls.
Select only the integer part in the formatted element content, whatever the value of selectNumberOnly
This instance for chaining method calls.
Select only the numbers in the formatted element content, leaving out the currency symbol, whatever the value of the selectNumberOnly
option
This instance for chaining method calls.
Set the given element value, and format it immediately.
Additionally, this set()
method can accept options that will be merged into the current AutoNumeric element, taking precedence over any previous settings.
The value must be a Number, a numeric string or null
(if emptyInputBehavior
is set to null
)
A settings object that will override the current settings. Note: the update is done only if the newValue
is defined.
If set to true
, then the change is recorded in the history table
This instance for chaining method calls.
Set the given value directly as the DOM element value, without formatting it beforehand.
You can also set the value and update the setting in one go (the value will again not be formatted immediately).
New value to set.
New options to set.
This instance for chaining method calls.
Update the settings to use the Spanish pre-defined language options. Those pre-defined options can be overridden by passing an option object as a parameter.
Optional options to override the pre-defined options.
This instance for chaining method calls.
Update the settings to use the Swiss pre-defined language options. Those pre-defined options can be overridden by passing an option object as a parameter.
Optional options to override the pre-defined options.
This instance for chaining method calls.
Remove the formatting and keep only the raw unformatted value (as a numericString) in each element of the local AutoNumeric element list
This instance for chaining method calls.
Remove the formatting and keep only the localized unformatted value in the element, with the option to override the default outputFormat if needed
If set to something different from null
, then this is used as an overriding outputFormat option
This instance for chaining method calls.
Updates the AutoNumeric settings, and immediately format the element accordingly.
New options to set. When multiple options are specified, later options override previous options.
This instance for chaining method calls.
Remove the autoNumeric data and event listeners from the element, and reset its value to the empty string. This also clears the value from sessionStorage (or cookie, depending on browser supports).
Return the AutoNumeric object that manages the given DOM element
Returns the unformatted value following the outputFormat
setting, from the given DOM element or query selector.
See the non-static getLocalized
method documentation for more details.
A string to localize, or a DOM element with a value to localize.
Override for the outputFormat
option.
Callback to invoke with the localized value.
The localized value.
Returns the unformatted value following the outputFormat
setting, from the given DOM element or query selector.
See the non-static getLocalized
method documentation for more details.
A string to localize, or a DOM element with a value to localize.
Callback to invoke with the localized value.
The localized value.
Return all the predefined options in one object
Return true if the given DOM element has an AutoNumeric object that manages it.
Unformats and localizes the given formatted string with the given options.
This basically allows to get the localized value without first having to initialize an AutoNumeric object.
The returned value may be either a string or a number, depending on the outputFormat
option.
A string to unformat and localize, or an input element with a value to unformat and localize.
Optional options to use instead of the current options of this instance.
The localized value.
Unformats and localizes the value of the given element with the given options, then sets the localized value on the element.
This basically allows to set the localized value without first having to initialize an AutoNumeric object.
The returned value may be either a string or a number, depending on the outputFormat
option.
Optional options to use instead of the current options of this instance.
The localized value.
Merge the current options with the given list of options.
If a string
is given, then we try to get the related pre-defined option using that string as its name.
When merging the options, the latest option overwrite any previously set. This allows to fine tune a pre-defined option for instance.
The merged options.
Enables the AutoNumeric feature for the given elements.
The DOM element must be one of the allowed elements. Allowed elements are <input>
, as well as some
other text-containing elements such <div>
. See the documentation for the full list.
When not an input
element, the element may have the contenteditable
set. If it does, all
entered values are formatted according to the given options. Otherwise, the formatted value is
set once and no further edits are possible.
A list of elements, which may be a CSS selector string.
Initial value to set. Can be an array to set a different value for each element. When null
, the
value of the DOM element is used.
AutoNumeric options. Can be an array to use a different set of options for each element.
Enables the AutoNumeric feature for the given elements.
The DOM element must be one of the allowed elements. Allowed elements are <input>
, as well as some
other text-containing elements such <div>
. See the documentation for the full list.
When not an input
element, the element may have the contenteditable
set. If it does, all
entered values are formatted according to the given options. Otherwise, the formatted value is
set once and no further edits are possible.
A list of elements, which may be a CSS selector string.
AutoNumeric options. Can be an array to use a different set of options for each element.
Set the given value on the AutoNumeric object that manages the given DOM element, if any.
DOM element with a value to unformat and set. Can be a CSS selector string.
The new value to set. Can be null
when emptyInputBehavior
is set to null
.
A settings object that will override the current settings. Note: the update is done only if the newValue
is defined.
If set to true
, then the change is recorded in the history table. Defaults to true
.
The AutoNumeric instance of the given element, or null
if no such instance was found.
Test if the given DOM element, or the element selected by the given selector string is already managed by AutoNumeric (if it has been initialized on the current page).
Whether the element is managed by AutoNumeric.
Unformats the given formatted string with the given options. This returns a numeric string.
It can also unformat the given DOM element value with the given options and returns the unformatted numeric string.
Note: This does not update that element value.
This basically allows to get the unformatted value without first having to initialize an AutoNumeric object.
The returned value might be a string or a number, depending on the outputFormat
option.
A number, or a string that represent a JavaScript number, or a DOM element with a value.
Optional to use instead of the default options.
The unformatted value.
Unformats the given DOM element value, and set the resulting value back as the element value.
The returned value might be a string or a number, depending on the outputFormat
option.
Optional to use instead of the default options.
The unformatted value.
Validate the given option object.
If the options are valid, this function returns nothing, otherwise if the options are invalid, this function throws an error.
This tests if the options are not conflicting and are well formatted.
This function is lenient since it only tests the settings properties ; it ignores any other properties the options object could have.
Options to validate.
If true
, then this function will extend the userOptions
passed by the user, with the default options.
The user can pass the original options (and not the one that are generated from the default settings and the various usability corrections), in order to add compatibility and conflicts checks.
Returns the AutoNumeric version number (for debugging purpose).
The current AutoNumeric version.
Generated using TypeDoc
The class constructor function is the exported object from the file