Angular 模式表单 - "required" 不工作 select 和复选框字段

Angular Schema Form - "required" not working select and checkbox fields

我是 Angular 架构表单的新手,在 selectcheckbox 字段 required 验证方面遇到了一些问题。

$scope.schema 下,我有一个名为 designation:

的 select 字段
"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 消息 underneath/after 字段。那不会发生。

我尝试过的事情:

请帮忙:)

您需要将架构类型更改为 string,因为 select 不是有效架构 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');
};