Skip to content

Commit e8bd4b0

Browse files
committed
2.2.6
1 parent 8f779fc commit e8bd4b0

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

dist/vue-numeric.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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": "2.2.5",
3+
"version": "2.2.6",
44
"description": "Input field component to display currency value based on Vue.",
55
"author": "Kevin Ongko",
66
"main": "dist/vue-numeric.min.js",

src/vue-numeric.vue

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export default {
173173
methods: {
174174
/**
175175
* Handle blur event.
176+
* @param {Object} e
176177
*/
177178
onBlurHandler (e) {
178179
this.$emit('blur', e)
@@ -181,16 +182,21 @@ export default {
181182
182183
/**
183184
* Handle focus event.
185+
* @param {Object} e
184186
*/
185187
onFocusHandler (e) {
186188
this.$emit('focus', e)
187-
this.amount = accounting.formatMoney(this.valueNumber, {
188-
symbol: '',
189-
format: '%v',
190-
thousand: '',
191-
decimal: this.decimalSeparator,
192-
precision: Number(this.precision)
193-
})
189+
if (this.valueNumber === 0) {
190+
this.amount = null
191+
} else {
192+
this.amount = accounting.formatMoney(this.valueNumber, {
193+
symbol: '',
194+
format: '%v',
195+
thousand: '',
196+
decimal: this.decimalSeparator,
197+
precision: Number(this.precision)
198+
})
199+
}
194200
},
195201
196202
/**

test/specs/vue-numeric.spec.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import VueNumeric from '@/vue-numeric'
66
import sinon from 'sinon'
77

88
describe('vue-numeric.vue', () => {
9-
it('has name', () => {
10-
const wrapper = mount(VueNumeric, { propsData: { value: 0 } })
11-
expect(wrapper.name()).to.equal('vue-numeric')
12-
})
13-
149
it('Use default decimal separator', () => {
1510
const wrapper = mount(VueNumeric, { propsData: { value: 2000 }})
1611
expect(wrapper.data().amount).to.equal('2,000')
@@ -177,6 +172,12 @@ describe('vue-numeric.vue', () => {
177172
expect(wrapper.data().amount).to.equal('2,000')
178173
})
179174

175+
it('clear the field if zero value', () => {
176+
const wrapper = mount(VueNumeric, {propsData: { value: 0, separator: '.', precision: 2 }})
177+
wrapper.trigger('focus')
178+
expect(wrapper.data().amount).to.equal(null)
179+
})
180+
180181
it('remove thousand separator and symbol on focus with , decimal', () => {
181182
const wrapper = mount(VueNumeric, {propsData: { value: 2000.21, separator: '.', precision: 2 }})
182183
wrapper.trigger('focus')
@@ -224,13 +225,13 @@ describe('vue-numeric.vue', () => {
224225
})
225226

226227
it('apply new separator immediately if it is changed', () => {
227-
const wrapper = mount(VueNumeric, { propsData: { value: 2000, separator: ',' } })
228+
const wrapper = mount(VueNumeric, { propsData: { value: 2000, separator: ',' }})
228229
wrapper.setProps({ separator: '.' })
229230
expect(wrapper.data().amount).to.equal('2.000')
230231
})
231232

232233
it('apply new currency prop immediately if it is changed', () => {
233-
const wrapper = mount(VueNumeric, { propsData: { value: 0, currency: '$' } })
234+
const wrapper = mount(VueNumeric, { propsData: { value: 0, currency: '$' }})
234235
wrapper.setProps({ currency: 'USD' })
235236
expect(wrapper.data().amount).to.equal('USD 0')
236237
})

0 commit comments

Comments
 (0)