alibaba / formily

📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3
https://formilyjs.org/
MIT License
11.48k stars 1.49k forks source link

[Feature] Schema Support name property #3664

Closed skyfore closed 1 year ago

skyfore commented 1 year ago

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Just see CodeSandbox

What is expected?

expect schema support name

希望 Schema 能够支持 name 属性,用于处理数据解构相关,然后本省的 name 用于设置联动,配置字段模型相关

What is actually happening?

not working

Package

@formily/react@2.2.16


janryWang commented 1 year ago

无法支持,因为目前json schema是基于properties的key来定义name的,如果支持name属性,那key与name属性会存在不一致的情况,这个以谁为准,说不清楚

skyfore commented 1 year ago

有没有可能一个单独的定义用来做解构数据,因为当我使用了解构作为 key 时,写联动逻辑出问题是会很难排查,比如

const schema = {
  '{ label: a, value: b }': {
    'x-component': 'Select'
  },
  b: {
    'x-component': 'Text'
  }
}

const effect = (form) => {
  // 这里的 key 很容易就会出现问题,比如空格少一个
  onFieldChange('{label: a, value: b }', (state) => {
    setFieldState('b', (field) => {
      field.value = state.value
    })
  })
}

// 希望的 schema 定义
const newSchema = {
  a: {
    dataName: '{ label: a, value: b }',
    'x-component': 'Select'
  },
  b: {
    'x-component': 'Text'
  }
}