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

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

Open
HAOYI99 opened this issue Dec 6, 2024 · 0 comments

Comments

@HAOYI99
Copy link

HAOYI99 commented Dec 6, 2024

提问前先看看:

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

🧐 问题描述

image
我写了个form,用来处理用户输入的数值 并且转换成json的prop

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

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

新增模式的log
image

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

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

💻 示例代码

<ProFormFieldSet
    name={PartProps.printing_time}
    label='Printing Time'
    rules={[{
        validator: (_, value: number[]) => {
            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
      }}
>
    <ProFormDigit
        noStyle
        placeholder=''
        min={0}
        max={120}
        fieldProps={{
            controls: false,
            suffix: 'hour'
        }}
    />
    <ProFormDigit
        noStyle
        placeholder=''
        min={0}
        max={59}
        fieldProps={{
            controls: false,
            suffix: 'min'
        }}
    />
</ProFormFieldSet>

期望结果

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

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

版本

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

@HAOYI99 HAOYI99 changed the title 🧐[问题] ProForm 🧐[问题] ProFormFieldSet 的convertValue 和transform在 新增form 和 编辑form 表现不一样 Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant