jd-opensource / drip-form

基于React和JSONSchema的动态表单解决方案

Home Page:https://jd-opensource.github.io/drip-form/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] <title>formData 初始化时和提交时的数据错误

guojinchao opened this issue · comments

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of DripForm、DripFormTheme.
  • I have read the console error message carefully (if applicable).

Description

复现步骤:

  1. 当前dripForm 配置了两个字段name和erp
  2. 在初始化时formData的值为 {jdName:"xxx", jdErp:"xxx"}
  3. 点击保存时我获取到的formData为{jdName:"xxx", jdErp:"xxx", name: "xxx", erp: "xxx"}

当前表单没有jdName和jdErp的输入框 所以在获取时也不应该返回这两个值

期望返回formData的值为: {name: "xxx", erp: "xxx"}

Steps to reproduce

复现步骤:

  1. 当前dripForm 配置了两个字段name和erp
  2. 在初始化时formData的值为 {jdName:"xxx", jdErp:"xxx"}
  3. 点击保存时我获取到的formData为{jdName:"xxx", jdErp:"xxx", name: "xxx", erp: "xxx"}

Current behavior

导致我初始化时传入的formData会在 提交表单时带上 一直叠加formData的值

Expected behavior

期望返回formData的值只根据配置的表单返回即可, 多余的值并不需要

Your environment

  • DripForm version used:
  • DripFormTheme used:
  • DripFormTheme version used:

Reproducible demo

No response

Self-service

  • I'd be willing to fix this bug myself.

请完善unitedSchema配置信息,方便排查

unitedSchema为:
{
"validateTime": "change",
"type": "object",
"title": "邮箱",
"ui": {},
"theme": "antd",
"schema": [
{
"validateTime": "submit",
"type": "string",
"title": "姓名",
"ui": {
"type": "text",
"style": {
"width": "100%"
}
},
"fieldKey": "name"
},
{
"validateTime": "submit",
"type": "string",
"title": "erp",
"ui": {
"type": "text",
"style": {
"width": "100%"
}
},
"fieldKey": "erp"
}
]
}

初始化时formData 为: {jdName:"xxx", jdErp:"xxx"}

提交保存时formData为: {jdName:"xxx", jdErp:"xxx", name: "xxx", erp: "xxx"}

jdName, 和 jdErp两个字段已经不在formJson里面了提交时 fromData的数据没有删掉

drip-form默认不会删除数据的多余字段,配置的schema只会处理配置的字段。
所以,我理解需要开放ajv配置。让用户选择不在schema中配置的字段是删除还是保留。
目前需要手动处理下多余数据。
这不是一个bug,而是一个feat。开发进度参考 #138
这里会关闭这个issue

#138 已经合并到主分支,下个版本支持配置ajvOptions prop 来自定义ajv配置

<DripForm
	unitedSchema={unitedSchema}
	uiComponents={{ 'drip-theme': dripTheme }}
        ajvOptions={{removeAdditional:'all'}}
/>

以上ajvOptions会自动删除多余字段。更多ajvOptions配置请参考ajv options
请关注后续发布日志