Meteorjs和autoform简单模式 - 如何验证简单的复选框

时间:2015-07-27 22:09:27

标签: meteor meteor-autoform

我正在使用autoform和简单模式,我已经使用以下字段定义了一个模式对象:

confirm_nominee: {

type: Boolean,
autoform: {
  type: "select-checkbox-inline",
  options: function () {
    return [
      {
        label: "Check here to certify that the volunteer nominated in the application is not a current member of the organization’s Board of Directors.",
        value: 1
      }
    ];
  }
}

},

我只是想要它,所以如果未选中该框,则错误报告“此字段是必需的”,如果已选中,则用户可以继续。

这似乎应该是一个非常简单的验证复选框是否被选中。我尝试添加defaultValue为0,但这也不起作用。

有什么想法?

非常感谢。

1 个答案:

答案 0 :(得分:1)

在架构规则中设置关键allowValues:[true],并且必须选中复选框为true并通过验证

confirm_nominee: {

type: Boolean,
autoform: {
  type: "select-checkbox-inline",
  allowedValues: [true],
  options: function () {
    return [
      {
        label: "Check here to certify that the volunteer nominated in the application is not a current member of the organization’s Board of Directors.",
        value: 1
      }
    ];
  }
}