Skip to content

Commit 2b957e2

Browse files
Format value if element is without focus
1 parent fca9f83 commit 2b957e2

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

spec/vue_numeric.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,49 @@ describe("vue-numeric", function() {
2828

2929
});
3030

31+
it('updates value with format if without focus', done => {
32+
const vm = new Vue({
33+
el,
34+
data: function() {
35+
return {
36+
total: 0
37+
}
38+
},
39+
template: '<div><vue-numeric v-model="total"></vue-numeric></div>',
40+
components: { VueNumeric }
41+
}).$mount()
42+
43+
vm.total = 3000;
44+
45+
Vue.nextTick(() => {
46+
expect(vm.$el.firstChild.value.trim()).toEqual('3,000')
47+
done()
48+
});
49+
50+
});
51+
52+
53+
it('updates value without format', done => {
54+
const vm = new Vue({
55+
el,
56+
data: function() {
57+
return {
58+
total: 0
59+
}
60+
},
61+
template: '<div><vue-numeric v-model="total"></vue-numeric></div>',
62+
components: { VueNumeric }
63+
}).$mount()
64+
65+
vm.$el.firstChild.focus();
66+
vm.total = 3000;
67+
68+
Vue.nextTick(() => {
69+
expect(vm.$el.firstChild.value.trim()).toEqual('3000');
70+
done()
71+
});
72+
73+
});
74+
3175

3276
});

src/vue-numeric.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ export default {
251251
numberValue (val, oldVal) {
252252
if (this.amountValue !== val && this.amountValue === oldVal) {
253253
this.convertToNumber(val)
254+
if (this.$el !== document.activeElement) {
255+
this.formatValue(val)
256+
}
254257
}
255258
}
256259
},

0 commit comments

Comments
 (0)