我是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 ..."
}
designation
和agreeTerms
都在架构的required
属性中定义。
当我提交表单时,两个字段都会通过required
验证。我希望用户界面显示的是字段下方/之后的Required
条消息。那种情况没有发生。
我尝试的事情:
''
和null
,并将其与架构默认值相匹配。select
字段类型更改为object
;这工作并通过了所需的验证,但财产没有出现在模型中请帮助:)
答案 0 :(得分:0)
您需要将架构类型更改为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');
};