jonathanpmartins / v-money3

Vue3 currency input/directive mask
MIT License
103 stars 27 forks source link

Wrong behavior when replacing value #21

Closed botura closed 3 years ago

botura commented 3 years ago

Writing #20 I came up with this:

1) Go here: codesandbox 2) Select all content (crtl A or with mouse) 3) Type '123' and you will get 'R$ 100,23'

jonathanpmartins commented 3 years ago

Your issue was introduced solving this another issue https://github.com/jonathanpmartins/v-money3/issues/7 that is related to another issue in the old v-money: https://github.com/vuejs-tips/v-money/issues/35

By @leok85 "If I start the component with an integer value, for example 50, it should interpret it as number 50.00, but with the mask the input number stays as 0.50"

This lines of code were introduced to solve this problem

  if (!isNaN(input)) {
    input = Number(input).toFixed(fixed(opt.precision))
  }

When you "select all" and input the first "1", the component recognizes that as and integer 1 (one) and will process it accordingly. Next, the component moves the cursor to the far right and the cycle continues.

jonathanpmartins commented 3 years ago

Fixed in this line: https://github.com/jonathanpmartins/v-money3/blob/0099f17ecde536d7af10fe6ef6625f89200110aa/src/directive.js#L50

...available in 3.14.0 version.