lljj-x / vue-json-schema-form

基于Vue/Vue3,Json Schema 和 ElementUi/antd/iview3/naiveUi 等生成 HTML Form 表单,用于活动编辑器、h5编辑器、cms等数据配置;支持可视化生成表单Schema 。 Generate a form using Vue/Vue3, Json Schema and ElementUi/antdv/iview3/naiveUi
https://form.lljj.me/
Apache License 2.0
2.09k stars 428 forks source link

anyOf 切换选项时,设置的同名field值并没有更新 #174

Closed JackZhang1988 closed 2 years ago

JackZhang1988 commented 2 years ago

反馈问题请先查看文档和务必提供详细的复现代码,遵循如下格式,描述不清楚的问题将会直接关闭。

vue和ui框架

vue3、ui框架antd 2.2.8

问题描述

anyOf 切换选项时,设置了一个隐藏的type, 示例中在切换个人资料设置方式时,userInfo中的type值并没有更新,而是始终保持在第一次设置的值

如何复现

https://form.lljj.me/v3/#/demo?ui=VueAntForm&type=Test&schema={%22title%22:%22%E4%BA%BA%E5%91%98%E4%BF%A1%E6%81%AF%22,%22type%22:%22object%22,%22properties%22:{%22userInfo%22:{%22title%22:%22%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99%E8%AE%BE%E7%BD%AE%E6%96%B9%E5%BC%8F%22,%22anyOfSelect%22:{%22ui:widget%22:%22RadioWidget%22},%22anyOf%22:[{%22title%22:%22%E9%80%9A%E8%BF%87%E7%94%A8%E6%88%B7%E5%90%8D%E8%AE%BE%E7%BD%AE%22,%22required%22:[%22firstName%22],%22properties%22:{%22type%22:{%22ui:hidden%22:true,%22type%22:%22string%22,%22default%22:%22userInfo%22},%22firstName%22:{%22type%22:%22string%22,%22title%22:%22%E5%90%8D%E5%AD%97%22,%22default%22:%22Jun%22},%22lastName%22:{%22type%22:%22string%22,%22title%22:%22%E5%A7%93%22,%22default%22:%22Liu%22}}},{%22title%22:%22%E9%80%9A%E8%BF%87%E7%94%A8%E6%88%B7id%E8%AE%BE%E7%BD%AE%22,%22properties%22:{%22type%22:{%22ui:hidden%22:true,%22type%22:%22string%22,%22default%22:%22userId%22},%22idCode%22:{%22type%22:%22string%22,%22title%22:%22ID%22,%22default%22:%2210086%22}}}]}}}&formData={%22price%22:99999.99,%22userInfo%22:{%22type%22:%22userInfo%22,%22firstName%22:%22Jun%22,%22lastName%22:%22Liu%22},%22url%22:%22https://lljj.me%22,%22projects%22:[{%22url%22:%22https://www.demo.com%22}]}&uiSchema={}&errorSchema={}&formFooter={%22formItemAttrs%22:{%22wrapperCol%22:{%22span%22:24,%22offset%22:0}}}&formProps={%22inline%22:false,%22labelPosition%22:%22top%22,%22inlineFooter%22:false,%22layoutColumn%22:1,%22labelCol%22:{%22span%22:10},%22wrapperCol%22:{%22span%22:24}}

期望的结果

anyOf切换不同选项时,需要更新同名的field的值 .... image

lljj-x commented 2 years ago

这里会判断不同options如果有了相同的key,如果没有配置 const 属性都会直接复用。


这里是文档的demo有点错误,playground中是对的

lljj-x commented 2 years ago
"type": {
      "ui:hidden": true,
      "type": "string",
      "default": "userId"
  }

正确形式如下 ✅

"type": {
      "ui:hidden": true,
      "type": "string",
      "const": "userId",
      "default": "userId"
  }