2
2
<input
3
3
:placeholder =" placeholder"
4
4
:value =" value"
5
- @blur =" formatValue(amountValue) "
5
+ @blur =" formatValue"
6
6
@input =" processValue(amountValue)"
7
- @focus =" convertToNumber"
7
+ @focus =" convertToNumber(numberValue) "
8
8
ref =" numeric"
9
9
type =" tel"
10
10
v-model =" amount"
@@ -102,6 +102,14 @@ export default {
102
102
return this .formatToNumber (this .amount )
103
103
},
104
104
105
+ /**
106
+ * Number type from value props.
107
+ * @return {Number}
108
+ */
109
+ numberValue () {
110
+ return this .formatToNumber (this .value )
111
+ },
112
+
105
113
/**
106
114
* Number formatted minimum value.
107
115
* @return {Number}
@@ -204,7 +212,7 @@ export default {
204
212
* Format value using symbol and separator.
205
213
*/
206
214
formatValue () {
207
- this .amount = accounting .formatMoney (this .value , {
215
+ this .amount = accounting .formatMoney (this .numberValue , {
208
216
symbol: this .currency + ' ' ,
209
217
precision: Number (this .precision ),
210
218
decimal: this .decimalSeparator ,
@@ -221,10 +229,11 @@ export default {
221
229
},
222
230
223
231
/**
224
- * Remove symbol and separator on focus.
232
+ * Remove symbol and separator.
233
+ * @param {Number} value
225
234
*/
226
- convertToNumber () {
227
- this .amount = accounting .formatMoney (this . value , {
235
+ convertToNumber (value ) {
236
+ this .amount = accounting .formatMoney (value, {
228
237
symbol: ' ' ,
229
238
precision: Number (this .precision ),
230
239
decimal: this .decimalSeparator ,
@@ -233,6 +242,19 @@ export default {
233
242
}
234
243
},
235
244
245
+ watch: {
246
+ /**
247
+ * Watch for value change from other input.
248
+ * @param {Number} val
249
+ * @param {Number} oldVal
250
+ */
251
+ numberValue (val , oldVal ) {
252
+ if (this .amountValue !== val && this .amountValue === oldVal) {
253
+ this .convertToNumber (val)
254
+ }
255
+ }
256
+ },
257
+
236
258
mounted () {
237
259
// Check default value from parent v-model.
238
260
if (this .value ) {
0 commit comments