1

The goal here is to set all the .class values (.multiple) with the preset languages and being able to modify things like decimal places or remove the currency symbol.

This works only for one class.

new AutoNumeric('.num-format').french().update({decimalPlaces: 0});

or this.

new AutoNumeric.multiple('.num-format', 'French');
new AutoNumeric.multiple('.num-format', 'French').update({decimalPlaces: 0});

This WILL work with all the classes BUT I cant figure out how to do things like set the decimal places?

new AutoNumeric.multiple( '.num-format', AutoNumeric.getPredefinedOptions().French );

I have pretty much tried all the options imaginable.

Thanks.

diogenes
  • 1,865
  • 3
  • 24
  • 51

1 Answers1

0

You can proceed with 2 different ways:

  • Either pass all your different options object during the initialization; those will be merged together. If an option is defined in multiple option objects, then the latter object option will overwrite the previous one.
  • Or use forEach() on the given AutoNumeric element array to update the options in one call
// AutoNumeric initialisation for multiple elements
// Here you can see that multiple options objects can be added, and will be merged in the given order
const anElementsStatic = new AutoNumeric.multiple('.static > .num-format', 42, ['French', { decimalPlaces: 0 }]);

// AutoNumeric initialisation for multiple elements
const anElements = new AutoNumeric.multiple('.mod > .num-format', [61, 62, 63, 64], ['French', { decimalPlaces: 0 }]);
// ...then we can update the options globally for all 4 fields with one function call:
anElements[2].update({ decimalPlaces: 3 }); // Modify only a specific element in the array
anElements.forEach(a => a.update({ currencySymbol: '#' })); // Modify all elements at once

You can check how it works on this codepen.

Alex
  • 1,241
  • 13
  • 22