1

我是 Angular Schema Form 的新手,并且在select字段checkbox验证required方面遇到了一些问题。

$scope.schema我有名为的选择字段designation

"designation": {
    "title": "Designation",
    "type": "select",
    "default": undefined
}

$scope.form(声明designationagreeTerms):

{
    "key": "designation",
    "type": "select",
    "title": "Designation",
    "titleMap": [
        { value: undefined, name: "Select a designation" }, // first value
        { value: "Andersson", name: "Andersson" },
        { value: "Johansson", name: "Johansson" },
        { value: "other", name: "Something else..."}
    ]
},
{
    "key": "agreeTerms",
    "type": "checkbox",
    "title": "I agree to ..."
}

两者designationagreeTerms都在模式的required属性中定义。

当我提交表单时,两个字段都通过了required验证。我期望 UI 显示的是Required字段下方/之后的消息。那没有发生。

我尝试过的事情:

  • 将选择字段的第一个值分配给''null与架构默认值匹配。
  • select字段类型更改object为架构中的;这有效并通过了所需的验证,但该属性未显示在模型中

请帮忙 :)

4

1 回答 1

1

您需要将架构类型更改stringselect不是有效的架构type属性。

"designation": {
    "title": "Designation",
    "type": "string",
    "default": undefined
}

然后在你的表单标签中你应该有ng-submit="submitForm(ngform,modelData)"

<form sf-schema="schema" sf-form="form" sf-model="model" ng-submit="submitForm(ngform,modelData)" sf-options="option"></form>

然后在您的控制器中,您可以在提交时广播以验证:

$scope.submitForm = function(form) {
    // First we broadcast an event so all fields validate themselves
    $scope.$broadcast('schemaFormValidate');
};
于 2018-06-28T09:26:53.057 回答