|
1 | 1 | <template> |
2 | | - <input type="tel" :value="value" v-model="amount" ref="numeric" :placeholder="placeholder" @blur="processValue(amountValue)" @focus="formatValueToNumberType"> |
| 2 | + <input |
| 3 | + :placeholder="placeholder" |
| 4 | + :value="value" |
| 5 | + @blur="formatValue(amountValue)" |
| 6 | + @input="processValue(amountValue)" |
| 7 | + @focus="convertValueToNumberType" |
| 8 | + ref="numeric" |
| 9 | + type="tel" |
| 10 | + v-model="amount" |
| 11 | + > |
3 | 12 | </template> |
4 | 13 |
|
5 | 14 | <script> |
@@ -47,7 +56,7 @@ export default { |
47 | 56 | * Enable/Disable minus value. |
48 | 57 | */ |
49 | 58 | minus: { |
50 | | - default: true, |
| 59 | + default: false, |
51 | 60 | required: false, |
52 | 61 | type: Boolean |
53 | 62 | }, |
@@ -209,21 +218,29 @@ export default { |
209 | 218 | }, |
210 | 219 |
|
211 | 220 | /** |
212 | | - * Apply value to component. |
213 | | - * @param {Number} value |
| 221 | + * Format value using symbol and separator. |
214 | 222 | */ |
215 | | - updateValue (value) { |
216 | | - this.amount = accounting.formatMoney(value, { |
| 223 | + formatValue () { |
| 224 | + this.amount = accounting.formatMoney(this.value, { |
217 | 225 | symbol: this.currency + ' ', |
218 | 226 | precision: Number(this.precision), |
219 | 227 | decimal: this.decimalSeparator, |
220 | 228 | thousand: this.thousandSeparator |
221 | 229 | }) |
| 230 | + }, |
222 | 231 |
|
| 232 | + /** |
| 233 | + * Update parent component model value. |
| 234 | + * @param {Number} value |
| 235 | + */ |
| 236 | + updateValue (value) { |
223 | 237 | this.$emit('input', Number(accounting.toFixed(value, this.precision))) |
224 | 238 | }, |
225 | 239 |
|
226 | | - formatValueToNumberType () { |
| 240 | + /** |
| 241 | + * Remove symbol and separator on focus. |
| 242 | + */ |
| 243 | + convertValueToNumberType () { |
227 | 244 | this.amount = this.value |
228 | 245 | } |
229 | 246 | }, |
|
0 commit comments