Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
vue-autonumeric
Advanced tools
A Vue.js component that wraps the awesome AutoNumeric input formatter library
vue-autoNumeric wraps the awesome AutoNumeric library and generate an <input>
element managed by AutoNumeric.
Checkout the demo!
yarn add vue-autonumeric
# or
npm install vue-autonumeric --save
Note: In order to minimize the size of the vue-autoNumeric component, the AutoNumeric library dependency is not bundled with it.
This means you need to link the AutoNumeric library with either ways:
<head>
tag directly<!-- locally... -->
<script src="../node_modules/autonumeric/dist/autonumeric.min.js"></script>
<!-- ...or by using a CDN -->
<script src="https://unpkg.com/autonumeric"></script>
Then you need to tell Webpack to treat the AutoNumeric
dependency as external so that it does not try to bundle it.
Here is a really simple webpack.config.js
example that does that:
module.exports = {
entry : './src/vueAutonumericTest.js',
output : {
filename: './dist/bundle.js'
},
externals: {
AutoNumeric: 'AutoNumeric',
},
};
You can choose to directly import the AutoNumeric library in your source code.
First, install the autonumeric
dependency so that Webpack can find it using:
yarn add autonumeric
# or
npm install autonumeric --save
You will as usual be able to use the vue-autonumeric
component in your Vue components using:
import VueAutonumeric from '../src/components/VueAutonumeric.vue';
export default {
name : 'myComponent',
components: {
VueAutonumeric,
},
data() {
return {
//
};
},
}
However, when doing that if you want to be able to bundle all the scripts together with Webpack, you'll need to define an alias for the AutoNumeric
library in your Webpack config like so:
module.exports = {
entry : './src/vueAutonumericTest.js',
output : {
filename: './dist/bundle.js'
},
resolve: {
alias: {
AutoNumeric: 'autonumeric/dist/autoNumeric.min',
},
},
};
The AutoNumeric component can be instantiated the same way AutoNumeric
can.
With an option object:
<vue-autonumeric
v-model="myValue"
:options="{
digitGroupSeparator: '.',
decimalCharacter: ',',
decimalCharacterAlternative: '.',
currencySymbol: '\u00a0€',
currencySymbolPlacement: 's',
roundingMethod: 'U',
minimumValue: '0'
}"
></vue-autonumeric>
With a predefined option name:
<vue-autonumeric
v-model="myValue"
:options="'French'"
></vue-autonumeric>
With multiple option objects/predefined options:
<vue-autonumeric
v-model="myValue"
:options="['euro', { minimumValue: '0' }]"
></vue-autonumeric>
You can define the input placeholder using:
<vue-autonumeric
v-model="myValue"
:options="'euro'"
:placeholder="'Enter your value here'"
></vue-autonumeric>
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.
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.
Moreover, if you modify the :options
prop, the AutoNumeric settings will be automatically updated with the new options.
Please note that directly setting a :value='42'
on the <vue-autonumeric>
component will break it (really!).
Do NOT do that:
<vue-autonumeric
v-model="myValue"
:options="{ minimumValue: '0' }"
:value="42042.69" <!-- This fails -->
></vue-autonumeric>
The official AutoNumeric documentation is using this component extensively :)
An editable live example is available on Codepen.
Moreover, you can check the shipped examples in your browser, and study its source here.
^v4
^v2
This supports the same browsers than AutoNumeric supports:
(latest 2 versions)
If you use IE/Edge/Safari/Opera, this might work ;)
vue-autoNumeric
is open source and released under the MIT License.
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! :)
1.0.4
AutoNumeric
libraryFAQs
An AutoNumeric wrapper for Vue.js
The npm package vue-autonumeric receives a total of 913 weekly downloads. As such, vue-autonumeric popularity was classified as not popular.
We found that vue-autonumeric demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.