ant-design / ant-design/pro-components
🧐[问题] ProFormFieldSet 的convertValue 和transform在 新增form 和 编辑form 表现不一样
- 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
### 🧐 问题描述

我写了个form,用来处理用户输入的数值 并且转换成json的prop
在新增form里,
我可以很容易的处理,因为他直接就是`number[]`
我只需要在transform时写入指定 prop 就好
提交时候我需要把它变成string, 就是这样`{printing_time: "11:52"]}`
但在编辑form里,
如果我设置了initialValue,并且是string `"11:52"`
那么之后的value就会变得很奇怪
> 新增模式的log

> 这是编辑模式的log
> 第一行是打开edit form时候的log, 之后就是更改数值时候

> 他也会只显示第一第二数值

### 💻 示例代码
```
{
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
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