Skip to content

Commit 1c8c532

Browse files
committed
Currency symbol position
1 parent 1dff8c4 commit 1c8c532

File tree

2 files changed

+26
-57
lines changed

2 files changed

+26
-57
lines changed

spec/vue_numeric.spec.js

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -190,75 +190,25 @@ describe('vue-numeric', () => {
190190
})
191191
})
192192

193-
it('allow minus value when minus props is true', done => {
193+
it('updates value with currency symbol', done => {
194194
const vm = new Vue({
195195
el,
196196
data () {
197197
return {
198-
total: -100
199-
}
200-
},
201-
template: '<div><vue-numeric v-model="total" :minus="true"></vue-numeric></div>',
202-
components: { VueNumeric }
203-
}).$mount()
204-
205-
Vue.nextTick(() => {
206-
expect(vm.$el.firstChild.value.trim()).toEqual('-100')
207-
done()
208-
})
209-
})
210-
211-
it('disallow minus value when minus props is false', done => {
212-
const vm = new Vue({
213-
el,
214-
data () {
215-
return {
216-
total: -100
198+
total: 0
217199
}
218200
},
219-
template: '<div><vue-numeric v-model="total" :minus="false"></vue-numeric></div>',
201+
template: '<div><vue-numeric v-model="total" currency="CZK" currencySymbolPosition="sufix" precision=2 separator="."></vue-numeric></div>',
220202
components: { VueNumeric }
221203
}).$mount()
222204

223-
Vue.nextTick(() => {
224-
expect(vm.$el.firstChild.value.trim()).toEqual('100')
225-
done()
226-
})
227-
})
228-
229-
it('value cannot exceed max props', done => {
230-
const vm = new Vue({
231-
el,
232-
data () {
233-
return {
234-
total: 150
235-
}
236-
},
237-
template: '<div><vue-numeric v-model="total" :max="100"></vue-numeric></div>',
238-
components: { VueNumeric }
239-
}).$mount()
205+
//vm.$el.firstChild.focus()
206+
vm.total = 3000
240207

241208
Vue.nextTick(() => {
242-
expect(vm.$el.firstChild.value.trim()).toEqual('100')
209+
expect(vm.$el.firstChild.value.trim()).toEqual('3.000,00 CZK')
243210
done()
244211
})
245212
})
246213

247-
it('value cannot below min props', done => {
248-
const vm = new Vue({
249-
el,
250-
data () {
251-
return {
252-
total: 150
253-
}
254-
},
255-
template: '<div><vue-numeric v-model="total" :min="200"></vue-numeric></div>',
256-
components: { VueNumeric }
257-
}).$mount()
258-
259-
Vue.nextTick(() => {
260-
expect(vm.$el.firstChild.value.trim()).toEqual('200')
261-
done()
262-
})
263-
})
264214
})

src/vue-numeric.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ export default {
106106
default: '',
107107
required: false,
108108
type: String
109+
},
110+
111+
/**
112+
* Position of currency symbol
113+
* Symbol position props accept either 'sufix' or 'prefix' (default).
114+
*/
115+
currencySymbolPosition: {
116+
default: "prefix",
117+
required: false,
118+
type: String
109119
}
110120
},
111121
@@ -164,6 +174,14 @@ export default {
164174
thousandSeparator () {
165175
if (this.separator === '.') return '.'
166176
return ','
177+
},
178+
179+
/**
180+
* Define format for currency symbol and value.
181+
* @return {String} format
182+
*/
183+
formatString () {
184+
return this.currencySymbolPosition === 'sufix' ? '%v %s' : '%s %v';
167185
}
168186
},
169187
@@ -237,7 +255,8 @@ export default {
237255
*/
238256
formatValue () {
239257
this.amount = accounting.formatMoney(this.numberValue, {
240-
symbol: this.currency + ' ',
258+
symbol: this.currency,
259+
format: this.formatString,
241260
precision: Number(this.precision),
242261
decimal: this.decimalSeparator,
243262
thousand: this.thousandSeparator

0 commit comments

Comments
 (0)