ant-design / ant-design/pro-components

🧐[问题] ProFormFieldSet 的convertValue 和transform在 新增form 和 编辑form 表现不一样

Open
#8,907 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.8k
Forks
1.4k
Avg merge
10h 44m
Merged PRs (30d)
3

Description

提问前先看看:

https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md

### 🧐 问题描述
![image](https://github.com/user-attachments/assets/555b34c3-94ad-4098-908c-7a0abc765199)
我写了个form,用来处理用户输入的数值 并且转换成json的prop

在新增form里,
我可以很容易的处理,因为他直接就是`number[]`
我只需要在transform时写入指定 prop 就好
提交时候我需要把它变成string, 就是这样`{printing_time: "11:52"]}`

但在编辑form里,
如果我设置了initialValue,并且是string `"11:52"`
那么之后的value就会变得很奇怪

> 新增模式的log
![image](https://github.com/user-attachments/assets/7eb68177-6309-47ed-bf54-56b7ff62e939)

> 这是编辑模式的log
> 第一行是打开edit form时候的log, 之后就是更改数值时候
![image](https://github.com/user-attachments/assets/8be3fe33-5ca4-40cb-b3ea-8673f7204abc)

> 他也会只显示第一第二数值
![image](https://github.com/user-attachments/assets/7e85178c-7e43-4e9a-b121-97699dcbeb76)

### 💻 示例代码
```
{
const [hours, minutes] = value || [];
if (!hours || minutes == null) {
return Promise.reject('Please input valid Printing Time')
}
return Promise.resolve()
}
}]}
required
transform={(value) => {
console.log('transform', value)
return {
[PartProps.printing_time]: `${value[0]}:${value[1]}`
}
}}
convertValue={(value) => {
console.log('convert', value)
return value
}}
>

```

### 期望结果

当然我也尝试过直接在initialValue转换成`[11,52]`,这个就成功

但我希望可以convertValue上处理这个转换

### 版本
"@ant-design/pro-components": "^2.8.2",
"antd": "^5.22.3",

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied ProFormFieldSet example in both add and edit forms, using the stated @ant-design/pro-components and antd versions. Inspect the ProFormFieldSet handling of convertValue, initialValue, and transform; done means an initial string such as "11:52" is converted consistently to the two numeric fields without breaking submission transformation.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.