2

我正在使用以下架构和表单。请检查下面的 JSFiddle 以了解其行为方式。当我对“我必须同意”说“是”但没有选中“同意”并单击“保存”按钮时,我希望表单无效。看起来我首先必须选择同意,然后取消选择它才能显示验证消息。 http://jsfiddle.net/mutharasus/Ljp7bhgn/

$scope.schema = {
  "type": "object",
  "properties": {
    "doIHaveToAgree": {"type": "boolean"},
    "agree": { "type": "boolean" }
   },
   "required": ["doIHaveToAgree"]
};


$scope.form = [
    {
        "key":"doIHaveToAgree",
        "title": "Do I have to agree",
        "type":"radios-inline",
        "titleMap":[{"value":true,"name":"Yes"},{"value":false,"name":"No"}]
    },
    {
    "key": "agree",
    "condition": "model.doIHaveToAgree",
    "validationMessage": {
        "agreeRequired": "You have to agree"
    },
      "$validators": {
          "agreeRequired": function(value){
              return value;
          }
      }
  },
  {
    "type": "submit",
    "title": "Save"
  }
];

这似乎是由于https://github.com/Textalk/angular-schema-form/issues/388

我不想要求“同意”,因为这仅适用于 UI。在服务器端,当“doIHaveToAgree”为假时,模式验证将失败。

由于没有作为事件的一部分调用,我有什么方法可以$validate()手动触发现场?$validate()schemaFormValidate

4

0 回答 0