Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e4e9110

Browse files
committedMar 15, 2017
update parent component value on input
1 parent 5ef3d51 commit e4e9110

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed
 

‎README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66

77
Input field component to display currency value based on [Vue](https://vuejs.org/).
88

9-
``Works with Vue 2.*``
9+
`Works with Vue 2.*`
1010

1111
## Installation
1212

1313
```sh
1414
$ npm install vue-numeric --save
1515
```
1616

17-
1817
## Usage
1918

2019
![screen shot 2016-12-08 at 2 19 31 pm](https://cloud.githubusercontent.com/assets/15880638/21001265/f2322438-bd51-11e6-8985-f31a45702484.png)
@@ -65,7 +64,7 @@ Limit minimum and maximum input by using `min, max` props.
6564
```
6665

6766
### Disable/enable minus value
68-
- `minus` default to `true`.
67+
- `minus` default to `false`.
6968

7069
```vue
7170
<vue-numeric v-bind:minus="false"></vue-numeric>
@@ -101,7 +100,7 @@ By default the decimal value is disabled, to use decimal value add `precision` p
101100
|default|Input default value|false|Number, String|-|
102101
|max|Maximum value allowed|false|Number, String|-|
103102
|min|Minimum value allowed|false|Number, String|0|
104-
|minus|Enable/disable minus value|false|Boolean|true|
103+
|minus|Enable/disable minus value|false|Boolean|false|
105104
|placeholder|Input placeholder|false|String|-|
106105
|precision|Number of decimals|false|Number, String|-|
107106
|separator|Thousand separator type ( accept either `.` or `,` )|false|String|,|

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-numeric",
3-
"version": "1.3.3",
3+
"version": "1.4.0",
44
"description": "Input field component to display currency value based on Vue.",
55
"author": "Kevin Ongko",
66
"main": "src/vue-numeric.vue",

‎src/vue-numeric.vue

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<template>
2-
<input type="tel" :value="value" v-model="amount" ref="numeric" :placeholder="placeholder" @blur="processValue(amountValue)" @focus="formatValueToNumberType">
2+
<input
3+
:placeholder="placeholder"
4+
:value="value"
5+
@blur="formatValue(amountValue)"
6+
@input="processValue(amountValue)"
7+
@focus="convertValueToNumberType"
8+
ref="numeric"
9+
type="tel"
10+
v-model="amount"
11+
>
312
</template>
413

514
<script>
@@ -47,7 +56,7 @@ export default {
4756
* Enable/Disable minus value.
4857
*/
4958
minus: {
50-
default: true,
59+
default: false,
5160
required: false,
5261
type: Boolean
5362
},
@@ -209,21 +218,29 @@ export default {
209218
},
210219
211220
/**
212-
* Apply value to component.
213-
* @param {Number} value
221+
* Format value using symbol and separator.
214222
*/
215-
updateValue (value) {
216-
this.amount = accounting.formatMoney(value, {
223+
formatValue () {
224+
this.amount = accounting.formatMoney(this.value, {
217225
symbol: this.currency + ' ',
218226
precision: Number(this.precision),
219227
decimal: this.decimalSeparator,
220228
thousand: this.thousandSeparator
221229
})
230+
},
222231
232+
/**
233+
* Update parent component model value.
234+
* @param {Number} value
235+
*/
236+
updateValue (value) {
223237
this.$emit('input', Number(accounting.toFixed(value, this.precision)))
224238
},
225239
226-
formatValueToNumberType () {
240+
/**
241+
* Remove symbol and separator on focus.
242+
*/
243+
convertValueToNumberType () {
227244
this.amount = this.value
228245
}
229246
},

0 commit comments

Comments
 (0)
Please sign in to comment.