vue-autoNumeric
A Vue.js component that wraps the awesome autoNumeric input formatter library
vue-autoNumeric wrap the awesome autoNumeric library and generate an <input>
element managed by AutoNumeric.
Installation
yarn add vue-autonumeric
npm install vue-autonumeric --save
You also need to link the AutoNumeric library in your html <head>
tag like so:
<script src="//unpkg.com/autonumeric"></script>
How to use?
The AutoNumeric component can be instantiated the same way AutoNumeric
can.
With an option object:
<autonumeric
v-model="myValue"
:options="{
digitGroupSeparator: '.',
decimalCharacter: ',',
decimalCharacterAlternative: '.',
currencySymbol: '\u00a0€',
currencySymbolPlacement: 's',
roundingMethod: 'U',
minimumValue: '0'
}"
/>
With a predefined option name:
<autonumeric
v-model="myValue"
:options="'French'"
/>
With multiple option objects/predefined options:
<autonumeric
v-model="myValue"
:options="['euro', { minimumValue: '0' }]"
/>
Other props
You can define the input placeholder using:
<autonumeric
v-model="myValue"
:options="'euro'"
:placeholder="'Enter your value here'"
/>
In the future, you'll be able to define the type of element tag (<p>
, <div>
, etc.) you want that component to generate.
This will allow you to create any supported tag with the contenteditable
attribute set to true
, instead of <input>
one as it is for now.
Integration with other scripts & events support
This wrapper supports setting the AutoNumeric options via an :options
prop.
It also supports external value changes (via aNElement.set(42)
for instance) and update the formatting and the v-model
accordingly.
The paste
, drop
and wheel
events are supported as well.
Caveats
Please note that directly setting a :value='42'
on the <autonumeric>
component will break it (really!).
Do NOT do that:
<autonumeric
v-model="myValue"
:options="{ minimumValue: '0' }"
:value="42042.69" <!-- This fails -->
/>
Demo
The official AutoNumeric documentation is will soon be using this component extensively :)
An editable live example is available on Codepen.
Requirements
Browser support
This supports the same browsers than AutoNumeric supports:
(latest 2 versions)
If you use IE/Edge/Safari/Opera, this might work ;)
License
vue-autoNumeric
is open source and released under the MIT License.
Support
As always, if you find this useful, please consider supporting its development!
Huge Thanks :)
Copyright © 2016 Alexandre Bonneau
PS:
I would love to know how you're using vue-autonumeric.
Contact me!