angular-schema-form默认值,隐藏值

时间:2017-01-31 18:38:11

标签: angularjs forms angular-schema-form

我想构建一个(部分)形式,它产生以下输出:

{
  ...
  offers: {
     context: "http://schema.org",
     minPrice: 3
  }
  ...
}

问题是,context应始终存在 - 用户可以操作的唯一字段是minPrice。马上就会想到一个有价值的隐藏场。所以这里是架构定义:

$scope.schema = {
  ...
  offers: {
    type: 'object',
    properties: {
      minPrice: {
        type: 'number'
      }
    }
  }
  ...
};

这里是表单定义:

$scope.form = [
  ...
  {
    key: 'offers',
    type: 'fieldset',
    items: [
      {
        key: 'offers.minPrice',
        type: 'number'
      },
      {
        key: 'offers.context',
        type: 'hidden',
        default: 'http://schema.org'
      }
    ]
  }
  ...
];

但是,观察生成的模型很明显,条目context不存在。我已成功使用type: 'hidden'defaulttabarray的组合,但我无法使用object来解决问题。我正在使用0.8.13的{​​{1}}版本 - 这是撰写本文时的最新版本。

感谢任何见解,谢谢。

1 个答案:

答案 0 :(得分:0)

您必须在该版本的架构中包含上下文及其默认值。

我希望你的问题与应该已经在v1.0.0的alphas中修复的错误有关

它应该与:

一起使用

<强>模式

{
  "type": "object",
  "properties": {
    "offers": {
      "type": "object",
      "properties": {
        "minPrice": {
          "type": "number"
        },
        "context": {
          "type": "string",
          "default": "http://schema.org"
        }
      }
    }
  }
}

<强>表格

[
  {
    "type": "fieldset",
    "items": [
      {
        "key": "offers.minPrice",
        "type":"number"
      },
      {
        "key": "offers.context",
        "type": "hidden",
        "notitle": true
      }
    ]
  }
]