0

我正在尝试使用 Angular JSON Schema Form 创建一个表单。我希望在填充另一个字段(number1)时需要一个字段(dropdown1)。我能够在SchemaForm.io Sandbox中获得以下表单 + 架构,但是当我将其放入我的站点时,下拉字段丢失。

这是我的架构:

{
"type": "object",
"properties": {
    "isChecked": {
        "title": "checked?",
        "type": "boolean"
    },
    "text1": {
        "title": "text1",
        "type": "number",
        "minimum": 0,
        "maximum": 100,
        "condition": "model.isChecked"
    },
    "number1": {
        "title": "number1",
        "type": "number",
        "minimum": 0,
        "condition": "model.isChecked"
    },
    "dropdown1": {
        "title": "",
        "type": "string",
        "enum": ["Days", "Months", "Years"],
        "condition": "model.isChecked"
    },
    "comment": {"type": "string", "Title": "Comment"}
}

}

这是我的表格:

[
"isChecked",
{
    "key": "text1",
    "type": "decimal",
    "validationMessages": {
        "maximum": "text1 must be 100 or lower.",
        "minimum": "text1 must be 0 or higher.",
        "required": "This field is required"
    },
    "required": false
},
{
    "key": "number1",
    "type": "number",
    "validationMessages": {
        "minimum": "number1 must be 0 or higher."
    },
    "required": false
},
{
    "key": "dropdown1",
    "required": false,
    "condition": "model.number1 === null"
},
{
    "key": "dropdown1",
    "required": true,
    "condition": "model.number1 > 0",
    "validationMessages": {
        "required": "dropdown1 is required."
    }
},
{
    "key": "comment",
    "type": "textarea"
}

]

4

2 回答 2

2

您可以使用“依赖项”属性(https://json-schema.org/understanding-json-schema/reference/object.html#property-dependencies)。该示例要求在提供 credit_card 时提供 billing_address:

{
  "type": "object",
  "properties": {
    "credit_card": {
      "type": "number"
    },
    "billing_address": {
      "type": "string"
    }
  },
  "dependencies": {
    "credit_card": [
      "billing_address"
    ]
  }
}

此实现支持“依赖项”: https ://github.com/dashjoin/json-schema-form

您可以在这里查看在线示例: https ://dashjoin.github.io/#/example/dependencies

于 2020-06-22T10:38:16.450 回答
0

这是我找到的解决方案:

"condition": {
                "functionBody": "return model.number1 === undefined && model.isChecked"
            }
于 2020-06-04T13:00:40.170 回答