Giter VIP home page Giter VIP logo

Comments (1)

lljj-x avatar lljj-x commented on May 11, 2024

对首次匹配结果做特殊处理,兼容配置 required 来区分 anyOf 的场景,如下数据可正常编辑匹配:

{
    "type": "object",
    "required": [
        "age"
    ],
    "anyOf": [
        {
            "ui:showTitle": true,
            "title": "First method of identification",
            "required": [
                "lastName"
            ],
            "properties": {
                "firstName": {
                    "type": "string",
                    "title": "First name",
                    "default": "Chuck"
                },
                "lastName": {
                    "type": "string",
                    "title": "Last name"
                }
            }
        },
        {
            "ui:showTitle": true,
            "title": "Second method of identification",
            "properties": {
                "firstName": {
                    "type": "string",
                    "title": "First name"
                },
                "idCode": {
                    "type": "string",
                    "title": "ID code",
                    "default": "Default id"
                }
            }
        }
    ]
}

针对anyOf 数据回写的场景,更保险的方式应该 结合 const 一起使用,const 可以约定包含的值必须为该结果,如下:

也可参见:https://form.lljj.me/#/demo?type=AnyOf%28%E8%81%94%E5%8A%A8%29

新增一个 type 字段,配置 const 和 default 判定当前的选中项,同时可以配置ui:hidden 来隐藏该项。

{
    "type": "object",
    "anyOf": [
        {
            "ui:showTitle": true,
            "title": "First method of identification",
            "properties": {
                "type": {
                    "ui:hidden": true,
                    "type": "string",
                    "default": "userName",
                    "const": "userName"
                },
                "firstName": {
                    "type": "string",
                    "title": "First name",
                    "default": "Chuck"
                },
                "lastName": {
                    "type": "string",
                    "title": "Last name"
                }
            }
        },
        {
            "ui:showTitle": true,
            "title": "Second method of identification",
            "properties": {
                "type": {
                    "ui:hidden": true,
                    "type": "string",
                    "default": "id",
                    "const": "id"
                },
                "firstName": {
                    "type": "string",
                    "title": "First name"
                },
                "idCode": {
                    "type": "string",
                    "title": "ID code",
                    "default": "Default id"
                }
            }
        }
    ]
}

from vue-json-schema-form.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.