[英]Angular Schema Form - “required” not working select and checkbox fields
我是Angular Schema Form的新手, select
和checkbox
字段存在一些问题, required
验证。
在$scope.schema
我有选择字段命名designation
:
"designation": {
"title": "Designation",
"type": "select",
"default": undefined
}
$scope.form
(声明designation
和agreeTerms
):
{
"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
属性中定义了designation
和agreeTerms
。
当我提交表单时,两个字段均通过了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.