@tagplus/components 1.2.16 → 1.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "email": "bruno@tagplus.com.br"
9
9
  }
10
10
  ],
11
- "version": "1.2.16",
11
+ "version": "1.2.19",
12
12
  "main": "./dist/tp.common.js",
13
13
  "directories": {
14
14
  "lib": "src/lib"
@@ -308,9 +308,17 @@ export default {
308
308
  this.setCurrentValue(newVal)
309
309
  },
310
310
  handleBlur (event) {
311
+ if (!this.value && this.stringDefaultsZero && !this.precision) {
312
+ this.currentValue = 0
313
+ }
314
+
311
315
  this.$emit('blur', event)
312
316
  },
313
317
  handleFocus (event) {
318
+ if (!this.value && !this.precision) {
319
+ this.currentValue = ''
320
+ }
321
+
314
322
  this.$emit('focus', event)
315
323
  },
316
324
 
@@ -33,17 +33,11 @@ function unformat (input, precision = defaults.precision) {
33
33
  * @returns
34
34
  */
35
35
  function formatMoney (input, toString = false, locale = defaults) {
36
- debugger
37
- let inputString = ('' + input)
38
- // Impede de digitar . ou , porque o formatador já adiciona
39
- if ((inputString.slice(-1).match(/[.,]/))) {
40
- inputString = inputString.substring(0, inputString.length - 1)
41
- }
42
- const negative = inputString.indexOf('-') >= 0 ? -1 : 1
36
+ const negative = ('' + input).indexOf('-') >= 0 ? -1 : 1
43
37
  const precision = locale.number.precision
44
38
 
45
39
  if (toString) {
46
- input = completeZeros(inputString, locale)
40
+ input = completeZeros(('' + input), precision)
47
41
  }
48
42
  const numbers = onlyNumbers(input, precision)
49
43
  const currency = numbersToCurrency(numbers, precision)
@@ -60,15 +54,13 @@ function formatMoney (input, toString = false, locale = defaults) {
60
54
  }
61
55
  }
62
56
 
63
- function completeZeros (input, locale) {
64
- const precision = locale?.number?.precision || defaults.precision
65
- const decimal = locale?.number?.decimal || defaults.decimal
66
- const i = input.indexOf(decimal)
57
+ function completeZeros (input, precision = defaults.precision) {
58
+ const i = input.indexOf('.')
67
59
  const qntDecimais = i ? input.length - i - 1 : 0
68
60
 
69
61
  // correção para decimal quebrado
70
62
  if (i === -1) {
71
- input = input + decimal + '0'.repeat(precision)
63
+ input = input + '.' + '0'.repeat(precision)
72
64
  } else if (i && qntDecimais < precision) {
73
65
  input = input + '0'.repeat(precision - qntDecimais)
74
66
  }