Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When InputNumber has a formatter attribute, it is not possible to enter a decimal with a negative zero point, such as -0.121 #6360

Open
1 task
wolfidea opened this issue Mar 16, 2023 · 7 comments
Labels

Comments

@wolfidea
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

3.3.0-beta.4

Environment

vue3 ant-design-vue 3.2.15

Reproduction link

Edit on CodeSandbox

Steps to reproduce

InputNumber 存在formatter属性时候,输入 -0.1 ,会被格式化成0.1

What is expected?

期望存在formatter时,可以输入 -0.121

What is actually happening?

一直存在

@github-actions github-actions bot changed the title InputNumber 存在formatter属性时候,无法输入负零点几的小数,比如-0.121 When InputNumber has a formatter attribute, it is not possible to enter a decimal with a negative zero point, such as -0.121 Mar 16, 2023
@tangjinzhou
Copy link
Member

remove min prop

@wolfidea
Copy link
Author

和min prop无关。
可以看Reproduction link里面第一个input-number,原因是存在formatter属性,会执行setInputValue方法,
setInputValue方法会即时格式化数据,NumberDecimal里面的 toString方法,会即时返回 this.origin,而 this.origin = String(value); 当输入-0的时候,这样就会即时返回String(-0),String(-0)的值是0,这样就会把负号给去除了。

暂时找到一个临时解决方法。 就是在自己的formatter方法里面拿input值,发现是-0,直接返回出来。
const formatter= (value, e) => {
const { input } = e;
if (input === '-0') {
return input;
}

// return value;
return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};

@zkwolf zkwolf added the bug label Mar 20, 2023
@tangjinzhou tangjinzhou added docs and removed bug labels Mar 21, 2023
@tangjinzhou
Copy link
Member

这就是个示例代码问题吧,组件不用动

@zkwolf
Copy link
Member

zkwolf commented Mar 21, 2023

可以看看ant design那边的例子,同样的输入行为是不一样的

@tangjinzhou tangjinzhou added bug and removed docs labels Mar 23, 2023
@tangjinzhou
Copy link
Member

可以看看ant design那边的例子,同样的输入行为是不一样的

@zkwolf 也有问题 https://codesandbox.io/s/ge-shi-hua-zhan-shi-antd-5-3-2-forked-481kor?file=/demo.tsx
他那个文档示例是 defaultValue 改成 value 一样有问题

@CCherry07
Copy link
Member

@tangjinzhou 这里好像是因为 输入-0 的时候 decimalValue.toNumber() 将 -0 变成了 0 然后双向绑定,最后的显示的值变成了0,我想这样去解决这个问题你怎么看?

const getDecimalValue = (stringMode: boolean, decimalValue: DecimalClass) => {
  if (stringMode || decimalValue.isEmpty()) {
    return decimalValue.toString();
  }

  const strVal = decimalValue.toString(false);
  if (/^-0$/.test(strVal)) {
    return strVal;
  }

  return decimalValue.toNumber();
};

@CCherry07
Copy link
Member

CCherry07 commented Mar 24, 2023

@wolfidea 您目前可以考虑使用 stringMode prop 处理你的问题
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants