Angular 模式表单 - 如果整数字段不为空则需要字段

Angular Schema Form - Require Field if Integer Field is Not Null

我正在尝试使用 Angular JSON 架构表单创建表单。我希望在填充另一个字段 (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"
}

]

这是我找到的解决方案:

"condition": {
                "functionBody": "return model.number1 === undefined && model.isChecked"
            }

您可以使用“依赖项”属性 (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