tusen-ai / naive-ui

A Vue 3 Component Library. Fairly Complete. Theme Customizable. Uses TypeScript. Fast.

Home Page:https://www.naiveui.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Currency PT-BR not working in Input Number

michelveloso opened this issue · comments

Describe the bug

I am using native-ui to format PT-BR (Brazil) currency.
However, even using a valid PT-BR format, even customizing the values ​​by functions, the value is not accepted.

Steps to reproduce

  1. access the codesandbox link (https://codesandbox.io/p/devbox/focused-edison-xwpmmw?file=%2Fsrc%2FApp.vue)

  2. Enter a valid value in PT-BR, for example: 1.285,45 the field will have a risk informed that the value is not valid
    image

  3. Enter a valid value in PT-BR, for example: 55.500,38 the amount will not be accepted
    image

Link to minimal reproduction

https://codesandbox.io/p/devbox/focused-edison-xwpmmw?file=%2Fsrc%2FApp.vue

System Info

"naive-ui": "^2.38.1"
"vue": "^3.4.21"
"vite": "^2.3.7",

Used Package Manager

yarn

Validations

It was actually a mistake on my part, I adjusted the function this way and it worked great!

const parseCurrency = (input: string) => {
  const nums = input.replace(/\./g, '').replace(',', '.').trim();  
  if (/^\d+(\.\d+)?$/.test(nums))
    return parseFloat(nums);

  return nums === '' ? null : Number.NaN;
};