繁体   English   中英

Angular Schema Form-“必需”不起作用的选择和复选框字段

[英]Angular Schema Form - “required” not working select and checkbox fields

我是Angular Schema Form的新手, selectcheckbox字段存在一些问题, 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 ..."
}

在模式的required属性中定义了designationagreeTerms

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

我尝试过的事情:

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

请帮忙 :)

您需要将架构类型更改为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');
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM