Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-numeric",
"version": "2.4.1",
"version": "2.4.2",
"description": "Input field component to display currency value based on Vue.",
"author": "Kevin Ongko",
"main": "dist/vue-numeric.min.js",
Expand Down
10 changes: 9 additions & 1 deletion src/vue-numeric.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export default {

mounted () {
// Set default value props when valueNumber has some value
if (this.valueNumber) {
if (this.valueNumber || this.isDeliberatelyZero()) {
this.process(this.valueNumber)
this.amount = this.format(this.valueNumber)

Expand Down Expand Up @@ -377,6 +377,14 @@ export default {
unformat (value) {
const toUnformat = typeof value === 'string' && value === '' ? this.emptyValue : value
return accounting.unformat(toUnformat, this.decimalSeparatorSymbol)
},

/**
* Check if value was deliberately set to zero and not just evaluated
* @return {boolean}
*/
isDeliberatelyZero () {
return this.valueNumber === 0 && this.value !== '';
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/specs/vue-numeric.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,8 @@ describe('vue-numeric.vue', () => {
wrapper.trigger('change')
expect(process.called).to.equal(true)
})
it('initial value is 0 if zero is passed', () => {
const wrapper = mount(VueNumeric, { propsData: { value: 0}})
expect(wrapper.data().amount).to.equal('0')
})
})