Skip to content

Updating existing options

Options can be added and/or modified after the initialization has been done.

Adding or modifing options

Either by passing an option object that contains multiple options,

anElement.update({ moreOptions });
anElement.update(AutoNumeric.getPredefinedOptions().NorthAmerican); // Update the settings (and immediately reformat the element accordingly) passing multiple option objects, the latter overwriting the settings from the former ones,

anElement.update({ moreOptions1 }, { moreOptions2 }, 'euro');
// or in a single array
anElement.update([{ moreOptions1 }, { moreOptions2 }, 'euro']);

...or by changing the options one by one (or by calling a pre-defined option object).



Each option can be accessed as a function to update its value, ie. anElement.options.<optionName>(), where <optionName> can be any option name from the options list.


As soon as the options are modified, the AutoNumeric-managed input content is re-formatted accordingly.

Updating the options for multiple elements

If you've initialized your input with AutoNumeric.multiple(), you can use the returned Array1 to update all the AutoNumeric objects at once:

// AutoNumeric initialisation for multiple elements
const anElements = new AutoNumeric.multiple('.numeric', 42, ['French']);

// Update the options globally for all the inputs with one function call:
// Modify only a specific element in the array
anElements[2].update({ decimalPlaces: 3 });
// or modify all the elements at once
anElements.forEach(a => a.update({ currencySymbol: '#' })); // or .set(), etc.

Resetting options

At any point, you can reset the options by calling the options.reset() method. This effectively drop any previous options you could have set, then load back the default settings.

Reset the options to their default settings

Lastly, the option object can be accessed directly, thus allowing to query each options globally too.
This allows to inspect the current options used.

Access the current options as an object
anElement.getSettings(); // Return the options object containing all the current AutoNumeric settings in effect

  1. The AutoNumeric.multiple() function will always return an Array, even if there is only one element selected.